Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Can't get dropdown to display Array contents

    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:


    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>

  • #2
    Senior Coder
    Join Date
    Apr 2007
    Location
    Quakertown PA USA
    Posts
    1,028
    Thanks
    1
    Thanked 125 Times in 123 Posts
    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.
    John

  • Users who have thanked PappaJohn for this post:

    philadendron (05-05-2011)

  • #3
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    In addition to what PappaJohn pointed out, you need to add an applicationComplete event to trigger the HTTPService call onload. The event method should do something similar to this:
    Code:
    userService.send();
    You are also going to have to deal with some type-casting issues since your retrieved object will be a different type.

  • Users who have thanked Inigoesdr for this post:

    philadendron (05-05-2011)

  • #4
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by PappaJohn View Post
    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.

  • #5
    New to the CF scene
    Join Date
    May 2011
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Inigoesdr View Post
    In addition to what PappaJohn pointed out, you need to add an applicationComplete event to trigger the HTTPService call onload. The event method should do something similar to this:
    Code:
    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()


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •