PDA

View Full Version : Can't get dropdown to display Array contents


philadendron
05-05-2011, 05:54 AM
Hi, I'm a student in an intro to flex dev class and I'm having trouble getting a dropdown to display the contents of an ArrayList. The ArrayList should be getting its data from an httpservice XML file. When I run the app, the dropdown is empty. Can you guys help me? I have to be able to do this for my final and it's driving me nuts. Here's the entire code:



<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<fx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;

[Bindable]
private var usersArray:ArrayCollection = new ArrayCollection();




protected function userService_resultHandler(event:ResultEvent):void
{
usersArray = event.result.main.users;
}



]]>
</fx:Script>
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<mx:HTTPService url="http://pr.uphero.com/users.xml" id="userService" result="userService_resultHandler(event)">

</mx:HTTPService>
</fx:Declarations>

<mx:Form x="76" y="61">
<mx:FormItem label="Label">
<s:DropDownList labelField="FirstName" dataProvider="{usersArray}"></s:DropDownList>
</mx:FormItem>
</mx:Form>
</s:Application>

PappaJohn
05-05-2011, 06:20 AM
Since this is for a class, I'll won't provide any code. But, I will suggest you take a look at the xml returned from the url in your HTTPService - the assignment to usersArray in your result handler does not match the structure of the xml.

Inigoesdr
05-05-2011, 07:12 AM
In addition to what PappaJohn pointed out, you need to add an applicationComplete event (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/Application.html#includeExamplesSummary) to trigger the HTTPService call onload. The event method should do something similar to this:
userService.send();
You are also going to have to deal with some type-casting issues since your retrieved object will be a different type.

philadendron
05-05-2011, 03:28 PM
Since this is for a class, I'll won't provide any code. But, I will suggest you take a look at the xml returned from the url in your HTTPService - the assignment to usersArray in your result handler does not match the structure of the xml.

Good call, the table and database name were swapped. I changed that, still no go, but I'll look into what Inigoesdr said as well. Thanks.

philadendron
05-05-2011, 03:36 PM
In addition to what PappaJohn pointed out, you need to add an applicationComplete event (http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/Application.html#includeExamplesSummary) to trigger the HTTPService call onload. The event method should do something similar to this:
userService.send();
You are also going to have to deal with some type-casting issues since your retrieved object will be a different type.

Got it, I was wondering how the httpservice was actually executed. I added a creationcomplete=appcreate handler, and added userService.send, but I get an error. I suspect it's related to what you said about typecasting. The error I get is:

TypeError: Error #1034: Type Coercion failed: cannot convert mx.utils::ObjectProxy@1d1d2a01 to mx.collections.ArrayCollection.
at exam/userService_resultHandler()[/Users/phil/Desktop/IS 380/workspaces/FiaW_Day4_ProjectArchive/exam/src/exam.mxml:18]
at exam/__userService_result()[/Users/phil/Desktop/IS 380/workspaces/FiaW_Day4_ProjectArchive/exam/src/exam.mxml:31]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at HTTPOperation/http://www.adobe.com/2006/flex/mx/internal::dispatchRpcEvent()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\http\HTTPService.as:989]
at mx.rpc::AbstractInvoker/http://www.adobe.com/2006/flex/mx/internal::resultHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AbstractInvoker.as:318]
at mx.rpc::Responder/result()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\Responder.as:56]
at mx.rpc::AsyncRequest/acknowledge()[E:\dev\4.x\frameworks\projects\rpc\src\mx\rpc\AsyncRequest.as:84]
at DirectHTTPMessageResponder/completeHandler()[E:\dev\4.x\frameworks\projects\rpc\src\mx\messaging\channels\DirectHTTPChannel.as:446]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()