To access the names of the fields in the ArrayCollection collection

Hello, this can seem like a n00b question, but, I have a collection of table that looks to the below:

public var topFive:ArrayCollection = new ArrayCollection([)
{Month: "GAME_Redemptions"},
{Month: "TALLINK_Redemptions"},
{Month: "YvesRocher_Redemptions"},
{Month: "ETAM_Redemptions"}
]);

With a loop, for example, if I want to access the value, I would type, topFive [i] .month. However, if I want to access domain name, what would be the code. IM assuming that it would be something like [i] topFive - but it does not return the desired result.

Does anyone know how to do this? I wanted to avoid having to put the table in a datagrid control and then extract values from there.

Help, please!

Craig

Your ArrayCollection collection contains five dynamic objects. If the expression 'topFive [i]' will give you the object at index 'i', rather than the Month of this object property. If you do not know the names of the properties of these objects then you need in order to access their properties a second loop:


<>
"xmlns:MX ="http://www.adobe.com/2006/mxml"
Layout = "vertical" >
   
   
        Import mx.collections.ArrayCollection;
           
private var topFive:ArrayCollection = new ArrayCollection([)
{Month: "GAME_Redemptions"},
{Month: "TALLINK_Redemptions"},
{Month: "YvesRocher_Redemptions"},
{Month: "ETAM_Redemptions"}
]);
           
private void doLoop(): void
{

Loop through the objects in the collection
for each (var item: object in topFive)
{

Loop in the properties of the current object.
for (var property: String in object)
{

Display the name of the current property and the value it contains
output. Text += property + ":"+ object [property] + '\n'; '.
}
}
}
           
]]>
   
   
    <>
label = 'Do Loop'
Click = "doLoop ()" / > "
       
    <>
Width = "200".
Height = "300".
ID = "output" / >
   

Tags: Flex

Similar Questions

  • How to access the Flex collection ArrayCollection in Action Script components?

    I have this code-

    < mx:Label text = "Style" / >
    < mx:ComboBox id = "cboStyle" initialize = "{changeSkin('skins/Plain.swf') ;} "change ="{changeSkin (cboStyle.selectedItem.data) ;} ">
    < mx:ArrayCollection >
    < mx:Object label = "Plain" data="skins/Plain.swf"/ >
    < mx:Object label = "BlueTan" data="skins/BlueTan.swf"/ >
    < mx:Object label = "Brauwny" data="skins/Brauwny.swf"/ >
    < mx:Object label = "Darknite" data="skins/Darknite.swf"/ >
    < mx:Object label = "iCandy" data="skins/iCandy.swf"/ >
    < mx:Object label = "Minty" data="skins/Minty.swf"/ >
    < mx:Object label = "SimplicityGray" data="skins/SimplicityGray.swf"/ >
    < mx:Object label = "SummerSky" data="skins/SummerSky.swf"/ >
    < / mx:ArrayCollection >
    < / mx:ComboBox >

    I would like to do instead of initialize = "{changeSkin('skins/Plain.swf') ;} "East of refers to an item in the collection ArrayCollection.  How can I do this?  I'm relatively new to Flex.  I guess that there is a way to access the ArrayCollection collection and then access the individual table entry.

    Thank you

    Aaron

    Initialize = "{cboStyle.DataProvider.getItemAt (0) .data ;}}" »

    If this post has answered your question or helped, please mark it as such.

  • Access table in the arraycollection collection and add the item at the end of the table

    for
    
    
    "login_user":"XXX"},i);
    
    //mess2=sess_MessArr[i2];
    //mess1=dispArray[i2].fwchat_message
    
    //searchArray(mess2);}
    
    
    
    
    
    (var i:int = 0; i< dispArray.length; ++i){
    
    dispArray[i]. 
    dispArray.addItemAt({
    


    I have this code to try to access the values in the table in the arraycollection collection, but that's not it actually creates a value at the end of the arraycollection collection. can someone tell me what im doing wrong I basically want retransmits the individual tables in the arraycollection collection and add Login_user

    So, I guess your ArrayCollection collection holds an array of objects, as follows:

    public var myAC:ArrayCollection = new ArrayCollection([{first:"bob",last:"smith"},{first:"jim",last:"jones"},{first:"mary",last:"allen"}]);
    

    And you try to add a new property of login_user to each of them, right?

    for each (var obj:Object in myAC) {
         obj.login_user = obj.first + "83";
    }
    

    Each person would be firstly, properties last and login_user.  In my example above, all the login_user would set their name + number 83, so adjust you accordingly for your application.

    It is the ease (for each rock for this situation).  However, if you want to paste the iterative approach, you have published, you can try this:

    for (var i:int = 0; i < myAC.length; i++) {
         myAC.getItemAt(i).login_user = myAC.getItemAt(i).first + "83";
    }
    

    I think that the for each syntax is clearer, but anyway works the way I think you want.

  • Accessing the parent Collection

    Y at - it a Navto command or otherwise (yet) to return to a collection of parent?

    I am familiar with the go to URL command to access the home collection: goto://ApplicationViewState/library

    However, we would really like to be able to "get out" of an item to the collection parent without having to call the built upwards in the navigation bar.  Any help?

    Not yet, but it's on our list to address in the near future. We really want to get this in, as well as a way to link directly to the collections.

    Neil

  • get the fields of the arraycollection collection?

    I want to loop through a collection of table and access all the items (columns)

    the arrayCollection collection looks so

    .columnOne [1]
    .columnTwo [1]
    .columnThree [1]
    .columnfour [1]

    [Bindable] public var dataSet:ArrayCollection = new ArrayCollection();

    protected function application1_creationCompleteHandler(event:FlexEvent):void

    {

    TODO self-generating method stub

    var d: Array = new Array()

    var int count = 5;

    var c:Number, r: Number;

    for (var i: int = 0; i<>

    {

    c = Math.Floor (Math.Random () * 10)

    r = Math.Floor (Math.Random () * 10)

    d.push ({cost: i + 1})

    Recipes: 2 * i + 1

    });

    }

    dataSet.source = d;

    Call();

    }

    function call (): void

    {

    for each (var point: Object in dataSet)

    {

    (var key: string in point)

    {

    trace (Key)

    trace ([Key] Item)

    }

    }

    }

  • Is it possible to search the ArrayCollection collection by index?

    Hi all

    I know, we can loop and compare each element of the ArrayCollection collection to get the correct item that we want. Obveriously, performance is going to hurt and it is not a wise method of search. Can we create an index for the key field of each item? Or any other class offering such a feature?

    Thank you

    When you say "a clue" are you talking like one in a table of database index?  That is something that can speed up a search?

    I'm trying to understand your desire and I think that what I hear, is that you have an ArrayCollection collection contains a number of objects.   When you want to find a particular object, you have found a way to locate the desired instance to browse each item in the collection ArrayCollection and ask "this element is equal to the key of the object I'm looking for?   I think that you are concerned by the amount of time it can take.

    Go back decades to my knowledge of computer science, this is an o(n) algorithm where n is the number of items in the table.

    Now, if there was an 'index' (ala databases) on the data, so if this index have been sorted, you would be able to find your match in O (log n)

    You can pay an O (n log n) cost the sort index when the data structure is created, but if you have a large number of research, then it can pay for itself.

    I'm not aware of any function that will help you on this out of the box (but that doesn't mean not there does not exist, only that I don't know about it.)

    I would like to also truthly ask yourself "is it worth the cost?   How many items you will have a typical table?  How often do you locate an entry in this table?

    Neil

  • How to upgrade the ArrayCollection collection when running?

    Am facing a problem with the arraycollection collection...
    will have an arraycolelction like that...
    var dpHierarchy:ArrayCollection = new ArrayCollection([)
    {Region: "Application1"},
    {Region: "Demand2"},
    {Region: "Demand3"},
    [{Region: "APPROVISIONNEMENTS4"}]

    now what I'm looking for is... How to upgrade this arraycollection collection during execution using actions script?
    I need to update this collection table something like this...

    var dpHierarchy:ArrayCollection = new ArrayCollection([)
    {Region: "Application1", year: '2008'},
    {Region: "demand2', year: '2008'},
    {Region: "Demand3', year: '2008'},
    [{Region: "APPROVISIONNEMENTS4", year: '2008'}]

    How to add the year field in to existing collection arraycollection as shown in the example...

    Thanks in advance
    Pratap

    Hey get...

    I have to just give

    dpHierarchy [0] ['year'] = '2008 '.

    :-)

  • How to check whether or not the arraycollection collection is initialized

    Hi all

    I am bit new to use the collection arraycollection in flex. I'm having this particular scenario, where I get Server data in a table. So I have to check if the arracollection I created is initialized or not. If it is not initialized I need to initialize it or other wise, just add collection from table to table. Here is the code snippet

    currentTrajectory = new collection ArrayCollection (event.result as Array);

    var _multiTrajectoryEvent:MultiTrajectoriesEvent;

    _multiTrajectoryEvent = new MultiTrajectoriesEvent (MultiTrajectoriesEvent.DRAW_AUTO_TRAJ);

    If (!) (_multiTrajectoryEvent.trajectories.source is nothing))

    {

    _multiTrajectoryEvent.trajectories.addItem (currentTrajectory);

    }

    else

    {

    _multiTrajectoryEvent.trajectories = new ArrayCollection ([currentTrajectory]);

    }

    But unfortunately the above code does not work for me, because the arraycollection collection is not initialized first, there is no way of checking me if it is initialized later or not as the compiler gives me the error checking to null...

    Can any Walter suggest how can I check if the table collection is initialized or not?

    I would appreciate any suggestions and thouhgts for the same

    Thank you

    Akshay

    Sorry to say, but it's not the right approach...

    I'm abt don't know what is exactly done so I'll give a generic example...

    I have an ArrayCollection collection...

    private var arrC:ArrayCollection;

    Maybe it's getting used internally in several places, so you be sure if she be initialized already or not. Then use a code something like that...

    If (arrC! = null & arrC.length > 0)

    {

    ...

    ...

    }

    If you are using

    If (arrC.Length > 0)

    {

    ...

    ...

    }

    and it is not initialised it will give exceptional at the time to compile...

    For a logic if(a && b) be true both a and b must be true, so if same first one (a) is false it will not evaluate the second logic (b).

    Thus, the previous logic works.

    concerning

    Nishant

  • Export the ArrayCollection collection in XML file

    Hi all

    Is it possible to export a Flex ArrayCollection collection to an XML file.

    My collection of table is displayed in a datagrid as follows

    < mx:DataGrid = "360" x y = "120" width = "448" height = "200" dataProvider = "{questionsArr}" >
    < mx:columns >
    < mx:DataGridColumn headerText = "Issue" dataField = "issue" / >
    < mx:DataGridColumn headerText = dataField "Start" = "start" width = "40" textAlign = "center" / >
    < mx:DataGridColumn headerText = "Stop" dataField = "stop" width = "40" textAlign = "center" / >
    < / mx:columns >
    < / mx:DataGrid >

    And I want to output the XML to look like this

    < cue >
    "< question section =" "start =" "stop =" "/ >
    "< question section =" "start =" "stop =" "/ >
    "< question section =" "start =" "stop =" "/ >
    < / cue >

    Is this possible?  I mean all the data is ready, he just needs to be saved. .

    Hi djh88ukwb,

    Try something as shown below in the link by performing a loop through the arraycollection collection and forming the knots... the way you need...

    http://nsdevaraj.WordPress.com/2008/08/20/ArrayCollection-XML/

    Thank you

    Jean Claude Chari

  • How to get the child elements of the ArrayCollection collection?

    Hi all

    I want to analyze collection ArrayCollection and want the child node element.

    How to parse the arraycollection collection?

    for (var i: int = 0; i<>

    {if (arrayCollectionObject.getItemAt (i). Item is "requireditem")}

    your code

    break;

    }

    }

    Let me know if it helps

  • update of the arrayCollection collection

    Jin

    I have an arrayCollection collection each time it updates, I need to make some sort of a calculation, how can I do with mechanizm binding?

    Thank you
    Jean Michel

    There is an event collectionChange on the ArrayCollection collection that gets shot above power off when the ArrayCollection collection changes. You can capture this event and then sort the collection out of that.

    The reference of the language will give you a few details: http://livedocs.macromedia.com/flex/2/langref/index.html

    -Andy

  • Add a line of DataGrid using the ArrayCollection collection

    Work of one of these, when I hard code do it programmatically is not:

    Hard-coding approach 1 - *.
    var acData:ArrayCollection = new ArrayCollection();
    ...

    Each DataGridColum has a dataField like "col1", "col2", "col3", etc...
    Therefore, adding items like this works
    acData.addItem({col0:"testa",col1:"testb",col2:"testc",col3:"testd",col4:"teste"});)


    2 - programming approach *.
    But adding items like that does not work
    for (var j = 0; j < dataRows.length (); j ++) {}
    var t:String = [j] of dataRows m:System.NET.SocketAddress.ToString (); dataRows is of type XMLList, data are formatted as the format above
    I did a breakpoint to check and someone else watch the channel and it matches the format that works.
    acData.addItem (t);
    }

    When I try the second approach, I get all the content of the string in each cell of the grid, where, in the first approach, I get "tested" in the first column, "testb" in the second column (without quotes of course), etc...

    Anyone know why there is a difference or what I am doing wrong?

    Thanks in advance.


    I guess that's because in the second approach, you add a string to your ArrayCollection collection instead of an object as in the first approach:

    acData.addItem({col0:"testa",col1:"testb",col2:"testc",col3:"testd",col4:"teste"});) This is an object with the properties that you add to the ArrayCollection collection

    var t:String is dataRows [j] m:System.NET.SocketAddress.ToString ();. It is a string, not an object
    acData.addItem (t); you add a string to the ArrayCollection collection

    You must take your XML string and generate a new object, as in your first approach, using the End Sub

  • Access the ArrayCollection class MXML ActionScript collection?

    I have a MXML file that has a collection for my tree component arraycollection. I am overriding the updateDisplayList function to add lines to all of my nodes in the tree... However, I can't seem to understand how to access this ArrayCollection collection of inside the actionscript class?

    I tried the methods used to pass variables between two MXML files (like a popup window - which I've used in the past and it works very well).

    My actionscript class code is almost identical to this example here:

    http://www.iepl.NET/treeControlSample/treeControlSample.html

    In the example above, the data is static, but sometimes my data's going to change and I need to access the set dataProvider (collection ArrayCollection) in order to make the lines work well... This has been very frustrating for me! :)

    If someone knows a better way to reach gettign lines for brothers and sisters in a tree... Please let me know!

    Any help would be super duper awesome!

    I found the solution to this. My problem was similar to cheftimo was seen in this post:

    http://www.Adobe.com/cfusion/webforums/Forum/MessageView.cfm?forumid=60&CATID=585&ThreadId = 1367784 & enterthread = y

    The answer is to import the component you are trying to access the variable from and then call using mx.core.Application ' Application.application.'

    Thanks to Greg Lafrance!

  • to access the data in the ArrayCollection collection


    accountingdata:ArrayCollection = new ArrayCollection (ArrayUtil.toArray (event.result));

    where event.result is a VO comes from a remote call

    The original Version contains a declaration of the variables:
    var date
    amount of the var
    etc...


    In my opinion, I use accountingdata as a DataProvider for my DataGrid, at the same time I need to access the VO.date of accountingdata of type ArrayCollection collection.
    Can someone tell me please how to do this?

    Thank you

    accountingdata.getItemAt (n) .date;

    Tracy

  • Extract information from the arrayCollection collection

    Hello world

    I have a very simple problem, but I'm a new flex developer and I have no idea what to do.

    that I extracted information from a database by using a Web service in coldfusion.

    in flex, I recovered my query result in an arrayCollection collection

    private var tabInfosDriver:ArrayCollection

    Private function driverInfoHandler(event:ResultEvent):Sub

    tabInfosDriver = event.result as ArrayCollection; collection

    and if I give {tabInfosDriver} as a dataprovider to a DataGrid, the result of the query is displayed correctly, something like that.

    Header1 By tete2 Header3 Header4 Header5
    someValuevalue2someValue3someValue4someValue5


    now, I want to use header1 someValue to fill a textField instance.

    I tried:

    Label1.text = tabInfosDriver.getItemAt (1.0) m:System.NET.SocketAddress.ToString)

    but it wrong: the index table out of range and in any case, I want to use the name of the header field, which is the database table to call its value

    Label1.text = tabInfosDriver.getItemAt("header1").value.toString)

    What can I do? I don't know that it is easy to solve. I looked at all the methods of the collection arrayCollection object, but I can't understand wich one to use.

    Please forgive me of my language, I do not speak English very often.

    Dominic

    Often you can either return the data to the Flex application in standard object notation, or to reconfigure the data in this way once he returns to the Flex application in the result handler. The standard notation, to which I am referring is:

    {

    {key1: 'value 1', key2: "Value2", key3: "Value3"},

    {key1: 'value 1', key2: "Value2", key3: "Value3"},

    {key1: 'value 1', key2: "Value2", key3: "Value3"},

    {key1: 'value 1', key2: "Value2", key3: "Value3"}

    }

    So in this way the data is structured, already as an associative array, because such a table is really just an ActionScript object.

    If these data should be accessible in two ways:

    var tempVar:String = myObject.key1;

    var tempVar:String = myObject ["key1"];    (maybe myObject ["key1"])

    Moreover, this "standard object notation" is also known under the name of JSON and there are libraries for handling JSON to the format of the data in Flex, PHP, etc if you have not necessarily to treat it as JSON, which comes, which makes it a little more formal and provides additional APIs:

    http://code.Google.com/p/AS3corelib/

Maybe you are looking for

  • Cannot connect printer to mac - status is idle

    I'm fit to be tied for no reason at all, my HP Officejet 6500 printer is connected, but it won't print anything because it says that there is no connection. utility, says the status is idle - cannot figure this out for what whatever - what happens in

  • PowerPoint model with CVI theme...

    Okay, I think it's a stupid question, but it could save me time. I'll give a long presentation of LabWindows/CVI and I wonder if there are some model (or white or simple) powerpoint file with LabWindows/CVI/theme colors I could borrow. I don't like t

  • DNS probe finished no internet

    While trying to use the internet, I get the message 'dns probe finished no internet' I looked at other patches, but none are for Windows Vista.  Can anyone help please?  The absence of internet connection is driving me crazy!  Thank you

  • 3 third-party libraries that require Java 1.5

    Hello I try to use some 3rd party open source Java code in my application of BB, but are struggling to make it work.  Group code 3 requires Java 1.5 to run which I suspect is the question because when I use the classes in my project of BB, a message

  • The two blackBerry Smartphones, Slacker Radio and Pandora do not work

    OK, so a few days ago I was listening to the music of the Slacker Radio App and everything worked but there was absolutely no noise, so I just let go and used the music on my SD card. When I got home I restarted Slacker and there was still no sound,