![]() |
|
| Register | FAQ | Calendar | Mark Forums Read |
![]() |
![]() |
![]() |
|
||||||
| Flex the application development solution for creating and delivering cross-platform rich Internet applications . This forum topic is about Flex IDE and Flex SDK developement questions. |
![]() |
|
|
Thread Tools | Display Modes |
|
#1
|
||||||||||||
|
||||||||||||
|
I have tried many ways to solve the problem but i can't ... so i ask you for help today...
i have this MXML file in my project: Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="ordenReporteSrv.send()">
<mx:HTTPService id="ordenReporteSrv" url="assets/orden.xml" result="ordenReporteAC = new ArrayCollection(ordenReporteSrv.lastResult.orden.reporte.tema)"/>
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var ordenReporteAC:ArrayCollection;
private function ordenDataHandler(event:ResultEvent):void
{
ordenReporteAC = ordenReporteSrv.lastResult.orden.reporte.tema;
}
]]>
</mx:Script>
<mx:DataGrid id="datagrid" dataProvider="{ordenReporteAC}" dragEnabled="true" dragMoveEnabled="true" dropEnabled="true"/>
</mx:Application>
Code:
<?xml version="1.0" encoding="utf-8"?> <orden> <reporte> <tema id="cajon" titulo="Redondeo" inicio="1" va="1"/> </reporte> <!--<piensa> <tema id="tema" titulo="Estar Guars" inicio="1" va="1"/> </piensa> <mty> <tema id="tema" titulo="Otro titulo" inicio="1" va="1"/> </mty>--> </orden> Code:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@154c3141 to Array. at index/__ordenReporteSrv_result() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent() at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler() at mx.rpc::Responder/result() at mx.rpc::AsyncRequest/acknowledge() at ::DirectHTTPMessageResponder/completeHandler() at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/flash.net:URLLoader::onComplete() thanx in advance!! |
|
#2
|
||||||||||||
|
||||||||||||
|
i've found this error is a lil bug that can be fixed by adding more than 1 node in the parent node before passing the data to the ArrayCollection.
Thank you anyways. somebody has any good solution for this from actionscript? |
|
#3
|
|||||||||||
|
|||||||||||
|
Sorry so late just joined this forum.
Sorry I am late posting this as I just joined these forums. What you refer to is a bug in my opinion but easy enough to work around. You are correct it does happen only when you return 1 result. What happens is when only 1 result is returned it is returned as an ObjectProxy instead of an Array. So just check to see if in fact you are getting a ObjectProxy or ArrayCollection and if need be use the ArrayUtil.toArray to convert it. Here is example code the work around is quite simple.
Code:
import mx.utils.ArrayUtil;
if (event.result.rows.row is ArrayCollection) {
theArray = event.result.entries.day;
} else if (event.result.rows.row is ObjectProxy) {
theArray = new ArrayCollection(ArrayUtil.toArray(event.result.rows.row));
}
|
|
#4
|
|||||||||||
|
|||||||||||
|
same here..
![]() I'm just starting with flex. Bear with me. This is all from a tutorial I saw. I get a 1034 error type coercion failure saying it can't convert ArrayCollection to and Array. Code:
TypeError: Error #1034: Type Coercion failed: cannot convert mx.collections::ArrayCollection@6bafc11 to Array.
at index/sanDataHandler()
at index/__sanData_result()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at mx.rpc.http.mxml::HTTPService/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()
at mx.rpc::Responder/result()
at mx.rpc::AsyncRequest/acknowledge()
at DirectHTTPMessageResponder/completeHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="vertical"
creationComplete="sanData.send()">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.utils.ArrayUtil;
[Bindable]
private var sandwiches:ArrayCollection;
private function sanDataHandler(event:ResultEvent):void
{
//sandwiches=new ArrayCollection(event.result.sandwichMenu.sandwich);
sandwiches=new ArrayCollection(ArrayUtil.toArray(event.result.sandwichMenu.sandwich));
}
private function faultHandler(event:mx.rpc.events.FaultEvent):void
{
var faultInfo:String="fault description: "+event.fault.faultDetail+"\n\n";
faultInfo+="fault faultstring: "+event.fault.faultString+"\n\n";
mx.controls.Alert.show(faultInfo,"Fault Information");
var eventInfo:String="event target: "+event.target+"\n\n";
eventInfo+="event type: "+event.type+"\n\n";
mx.controls.Alert.show(eventInfo,"Event Information");
}
]]>
</mx:Script>
<mx:HTTPService id="sanData"
url="http://localhost/foosball/assets/sandwichData.xml"
result="sanDataHandler(event)"
fault="faultHandler(event)"/>
<mx:DataGrid dataProvider="{sandwiches}"/>
<mx:Label text="{sandwiches.getItemAt(3).name}"/>
</mx:Application>
Code:
<?xml version="1.0" encoding="utf-8"?>
<sandwichMenu>
<sandwich>
<name>Dagwood</name>
<bread>Hogie</bread>
<meat>Hot Beef</meat>
<spread>Mayo</spread>
<type>Cold</type>
</sandwich>
<sandwich>
<name>Crooks</name>
<bread>Whole Wheat</bread>
<meat>Tofu Slices</meat>
<spread>Mustard</spread>
<type>Grilled</type>
</sandwich>
<sandwich>
<name>Mountain</name>
<bread>Sourdough</bread>
<meat>Turkey</meat>
<spread>Mayo</spread>
<type>Triple Decker</type>
</sandwich>
<sandwich>
<name>Pacific</name>
<bread>Pumpernickel</bread>
<meat>Tuna</meat>
<spread>Mustard</spread>
<type>Cold</type>
</sandwich>
<sandwich>
<name>Shove</name>
<bread>Rye</bread>
<meat>Pastrami</meat>
<spread>Thousand Island</spread>
<type>Baked</type>
</sandwich>
<sandwich>
<name>Gloucester</name>
<bread>Whole Wheat</bread>
<meat>Turkey</meat>
<spread>Plain</spread>
<type>Triple Decker</type>
</sandwich>
</sandwichMenu>
|
|
#5
|
|||||||||||
|
|||||||||||
|
Thanks!
That little code snippet from tekati really helped... sorted my problems in one go! thanks a bunch!
|
|
#6
|
|||||||||||
|
|||||||||||
|
Thanks Tekati for me to.
|
|
#7
|
|||||||||||
|
|||||||||||
|
Yeah, I see what you mean, and it help me out a lot, I was getting there... however now I had another problem with this... and solved it, I donīt know if its a good approach, but it worked.
When instead of receiving an 2||> ArrayCollection, or an [1] ObjectProxy, I received {result.data=null} or/meaning a null result (actually its an SQL query, received in XML format) I had to solve it somehow... I did this: if(evt.result.data != null) { if (evt.result.data.images is ArrayCollection) { array2 = evt.result.data.images; } else if(evt.result.data.images is ObjectProxy) { array2 = new ArrayCollection(ArrayUtil.toArray(evt.result.data. images)); } } else { Alert.show("Your SQL query return ZERo Results","Null Data!"); } COULD YOU SHOW ME ANOTHER WAY?? |
|
#8
|
|||||||||||
|
|||||||||||
|
don't worry about null
Update: My bad, didn't test that null case until just now. I see the issue now. Read this -> he does a good job with it: http://theruntime.com/blogs/be-sharp...XML-Nodes.aspx
Old message: yo just wanted to say you shouldn't worry about that null data unless it's important to show that there's no data. If you convert the ObjectProxy into an Array though the ArrayUtil.toArray() your null object should be converted into an arraycollection of length = 0. thus no results should be recorded while looping through the array and it will be empty, which is equivalent to your null case. also, get rid of the {} for the ifs and elses. Flex best practises state that if you only have 1 line of code, do if --- line of code, else -- line of code vs if {} else {}. cheers, ayan www.ayanray.com Last edited by ayanray; 10th June 2009 at 15:27. Reason: update |
|
#9
|
|||||||||||
|
|||||||||||
|
final code
thought i'd post my code to show how i do it:
var versions:ArrayCollection; if(installersRaw[i].versions == null) versions = new ArrayCollection();else if(installersRaw[i].versions.version is ObjectProxy) versions = new ArrayCollection( ArrayUtil.toArray( installersRaw[i].versions.version ) );else if(installersRaw[i].versions.version is ArrayCollection) versions = installersRaw[i].versions.version;var m:int = versions.length; for(var j:int = 0; j < m; j++) { trace("Version:", versions[j].version);} |
|
#10
|
|||||||||||
|
|||||||||||
|
ArrayCollection Error
Running Leopard on Intel MccBook. Get Error Code -10810 when I try to open apps. At first, only TextEdit affected, then iTunes, then other apps, finally Safari.
A Restart returned the ability to open apps, but this has been happening for a week. Cant find what Error Code -10810 means. Does anyone know? |
![]() |
| Bookmarks |
| Thread Tools | |
| Display Modes | |
|
|