Today I got a problem using the ArrayCollection with the HTTPService.
The ArrayCollection class is a wrapper class that exposes an Array as a collection that can be accessed and manipulated using the methods and properties of the ICollectionView or IList interfaces.
Consider the following code write inside an mxml file :
[Bindable]
public var myList:ArrayCollection; //defined into the mx:Script block
<mx:HTTPService id="simpleHTS"
url="list.xml"
result="myList = new ArrayCollection(simpleHTS.lastResult.list.name)" />
<mx:ComboBox id="NameSelect"
dataProvider="{myList}"
labelField="user_name"
change="filterByName()"/>
The list.xml file is made up of :
<list>
<name>
<user_id>1</user_id>
<user_name>Thai</user_name>
</name>
.......
</list>
This code, apparently correct, doesn't work.
The alert error we got is a casting error fired by the flash Player 9. That's because I'm trying to push an ArrayCollection object into a new ArrayCollection. In fact it's like wheter the "simpletestCat.lastResult.list.name" item is just an arrayCollection Object type.
Make this test and on the result handler of the HTTPService:
<mx:HTTPService id="simpleHTS"
url="list.xml"
result="myList = new ArrayCollection(simpleHTS.lastResult.list.name)" />
Now in the mx:Script block handle the result :
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
[Bindable]
private var myList:ArrayCollection;
private function resultHandler(event:ResultEvent):void
{
myList = new ArrayCollection(simpleHTS.lastResult.list.name);
}
]]>
</mx:Script>
Continue reading "ArrayCollection and HTTPService problem" »


















