A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: How to access an array of objects for UI?

  1. #1
    Member
    Join Date
    Nov 2007
    Posts
    41

    How to access an array of objects for UI?

    Hhi all - I've successfully access a web service in as3 and pulled the xml from it into a large array of objects

    ie
    Code:
    array
            object
                    array
                              object
                                     property
                                     property
                                     array
                                          arrayItem[0]
                                     array
                                          arrayItem[0]
                                     property
                                     property
                                     array
                                          arrayItem[0]
                                          arrayItem[1]
                              object
                    property
                    property
                    property
    etc etc

    This has to be accessed at a later point by the UI in order to build itself. I can't figure out how to create a loop or method or whatever to access this array.

    I need several ways of accessing it, so maybe I'm thinking of a method called accessSpecificItem(propertyName:String); <- to set up each UI item
    traceOutAllItems(arrayName:Array); <- for testing
    countNumberOfItems(arrayName:Array); <- for the UI to figure out how many items it needs to build

    Any other suggestions on how I can access this data?

    cheers
    Last edited by sleazy_elfranko; 07-16-2009 at 11:05 AM. Reason: structure of array

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Your data is in xml, not an array so you can use the e4x operators to take most of the pain out of parsing: http://dispatchevent.org/roger/as3-e4x-rundown/

  3. #3
    Member
    Join Date
    Nov 2007
    Posts
    41
    Quote Originally Posted by neznein9 View Post
    Your data is in xml, not an array so you can use the e4x operators to take most of the pain out of parsing: http://dispatchevent.org/roger/as3-e4x-rundown/
    Hi - thanks for the link, I've bookmarked these; I've accessed the raw xml data from the web service stream using e4x, finding specific nodes and transfering them into my array. I wanted to have this array available in memory so that I could access it at any time after the xml has been parsed and stored with multiple methods, extracting the data I want from it depending on the requirement at the time.

    But I'm a little unclear on how to extract object based data in arrays. Obviously you access an array with myArray[0] or myArray[0][1] etc but how do you do it with objects that are stored array item?

    ta

    frank

  4. #4
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Ahhh - I see. Academically it would probably be easier to save your xml out to a variable declared outside of your onComplete handler but for the sake of explanation:

    PHP Code:
    var a:Array = [123];
    var 
    b:Array = [a, [456], new Array(789)];        //  these are all the same - just declared differently
    var c:Object = {arrayA:aarrayB:b};
    var 
    d:Array = [abc];

    trace(a[0]);        //  1
    trace(b[0]);        //  1,2,3  - this just traced all of a
    trace(b[0][1]);        //  2
    trace(c['arrayA'])    //  1,2,3  - trace all of a



    trace(c['arrayB'][0][1]);
    //  2: "arrayB" points to b, then the zeroth element in that (which is a) - within that index 1 is "2"

    trace(d[2]['arrayB'][1][1]);
    //  5: same as earlier but b is now inside another array 

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center