-
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
-
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/
-
Originally Posted by neznein9
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
-
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 = [1, 2, 3];
var b:Array = [a, [4, 5, 6], new Array(7, 8, 9)]; // these are all the same - just declared differently
var c:Object = {arrayA:a, arrayB:b};
var d:Array = [a, b, c];
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|