Add the object to the ArrayCollection collection

Hi all

I have an ArrayCollection collection which will be filled by a call remotely from java code.

The Collection is no longer bound to a ComboBox that is shownup in the Panel.

I tried to add an object to the collection of ArrayCollection iterated to 0th Index, whereas I could see this label of objects as the default label in the drop-down list box.

But when the drop-down list box is displayed, the first element of the returned list of JavaCode is shown as the default label.

See all present items in the drop-down list box, the label of objects which is added at Index 0 is seen, but when rendering this is not used as the default when appears on the display.

< mx:ArrayCollection id = "departments" / >

private void departmentResultHandler(event:ResultEvent):void
{
departments = event.result as ArrayCollection collection;
Department: Department of var = new Department();
department.departmentID = 0;
department.departmentName = "Department";
departments.addItemAt(department,0);
}

< mx:ComboBox id = "add_departmentID" dataProvider = "{services}" labelField = "departmentName" textAlign = "left" selectedIndex = "0" / >

As I can't download images screeshot here, these are the URL that displays the images and gives a clear picture of what explains

http://picasaweb.Google.com/narra.Madan/screenshots/photo#5118474206291402818

http://picasaweb.Google.com/narra.Madan/screenshots/photo#5118474206291402834

Please suggest where I have gone wrong

Kind regards
Madan

The problem is the timing. When you assign the event.result to departments, the result is bound to the drop-down list, and the first item is selected by default. When new items are added to the drop-down list, flex does not change the selected item to the new item. Yes, it's just saying to your drop-down list box to select the element 0 and it will show Department.

departments.addItemAt(department,0);
add_departmentID.SelectedIndex = 0;

You can also look at the use of the prompt property of the combo box. The prompt when comboBox.selectedIndex = - 1. Unless you need article of the Jet to be selectable, you can quickly define = 'Department' and then do:

private void departmentResultHandler(event:ResultEvent):void
{
departments = event.result as ArrayCollection collection;
add_departmentID.SelectedIndex = - 1;
}

Vygo

Tags: Flex

Similar Questions

  • 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.

  • 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

  • Flex 3: syntax to power the ArrayCollection collection in loop

    Hi, I'm a newb. I can't find an example how to do that. Examples would be greatl appreciated.

    I want to draw some technical data by filling the dataprovider for my chart with a collection of table (so far no problem). I want to poulate collection table by looping through a mathematical expression, and I can't understand the syntax for this. For example...

    [Bindable]
    private var myChartData:ArrayCollection = new ArrayCollection([)
    {vertNum:100, horizNum:100}
    ]);

    I want to browse and add more points by program, so if I loop 5 times I find myself with...

    [Bindable]
    private var myChartData:ArrayCollection = new ArrayCollection([)
    {vertNum:100, horizNum:100},

    {vertNum:110, horizNum:110},

    {vertNum:43, horizNum:120},

    {vertNum:88, horizNum:130},

    {vertNum:140, horizNum:140},

    etc...
    ]);

    The number of variables horizontal to draw ould be several hundred, so I don't want to set up a huge collection of static array with expressions in each location. I'd rather solve the expression as a loop iterates and populate the collection of table as he goes. But I don't have any idea how "word" which.

    Thank you!

    Here's an example of adding a simple formula data points using a random number generator and amplify the randomness. The process is just to create a new object for each iteration of the loop and add the object to your ArrayCollection collection. You can assign as many properties to the object you need, which can be useful to use an ArrayCollection collection that appears in several charts.


    http://www.Adobe.com/2006/mxml"layout ="absolute"creationComplete =" build_model () ">"
       
            Import mx.collections.ArrayCollection;
               
    private function build_model (): void {}
    var obj:Object;
    var chartAC:ArrayCollection = new ArrayCollection();
                   
    for (var i: uint = 0; i< 100;="" i++)="">
    obj = new Object();
    obj.horizNum = 100 + 10 * i;
    obj.vertNum = i * Math.Random ();
    chartAC.addItem (obj);
    }
    linechart1. DataProvider = chartAC;
    }

    ]]>
       
       
           
               
           

       

       

    Chris

  • 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

  • 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 '.

    :-)

  • 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

  • Object to an ArrayCollection collection

    Hello

    I have an application that supports some info from database and he sinks into a datagrid, or a chart.

    I met this error to have one line and try to use it in a table so that I can use in my application.  Its come to my attention that it is a quite common problem that people face, but I don't seem to be able to get around any one test.

    My actionscript has a function that trots through ASP database and returns the data in the case - as below (obv I deleted stuff - load of calls are made to the mssqlQuery function - the only one I have trauma with is below)

    mssqlQuery ("SELECT (CASE SLARag, COUNT (SLARag) as Volume [CMI_ClientMI]. [Portal]. [BatchUpdate]","BusSegBuildSummary") ;}

    public static void mssqlQuery(sql:String,fid:String):void {}

    var http:HTTPService = new HTTPService;

    var parm:Object = new Object;

    parm.fas_sql = sql;

    parm.fas_db = mssql_db;

    http.url = mssql_url + "? irand =" + Math.random ();

    http.showBusyCursor = true;

    http.request = sql;

    http.addEventListener (ResultEvent.RESULT, mssqlResult);

    http.addEventListener (FaultEvent.FAULT, mssqlFault);

    http.method = "POST";

    sqlToken = http.send (parm);

    sqlToken.param = fid;

    }

    For BusSegBuildSummary collection arraycollection var

    [Bindable]

    public static var _BusSegBuildSummary:ArrayCollection = new ArrayCollection();


      

    Case statement to BusSegBuildSummary

    case 'BusSegBuildSummary':

      


    If (event.result.results.record is ObjectProxy) {}

    trace ("this is a Proxy object");


    }

    else {}

    trace ("it isn't Proxy object");

    _BusSegBuildSummary = event.result.results.record;

    }

    break;

    So - if the result has several records in it - so we are very well - it's the trace ("this is Proxy object"); bit which is annoying.

    I think I have to send the object as an arraycollection collection and I tried a number of different ways without success.

    Any ideas? I struggled for a while now and I am panicing!

    Hi Andrew

    No problem with the warranty so I wanted just report to disseminate good practices

    I do not understand what you write, but it is how I read it:

    When the user runs the function again, you get a more added slice, you can don't wan't, only you don't wan't the new?

    This is because you don't collection.addItem (item), so just add the to it to the collection.

    If you need to do:

    If (event.result.results.record is ObjectProxy)

    {

    collection.removeAll ();

    collection.addItem (event.result.results.record)

    }

    Best regards

    Martin

  • How to tell if ObjectProxy contains the ArrayCollection collection or single object?

    When I retrieve data from a web service, the list contains an ArrayCollection collection. Within each collection ArrayCollection, the element can be a single object or a collection of objects theser ArrayCollection. It seems that FLEX provides what he thinks it's the ObjectProxy object type based on the number of children under the parent node.

    If the done ObjectProxy refers to an ArrayCollection collection, I want to iterate on it, but if she refres to a single object, I want to remove some of its properties.

    How do I tell at runtime if an ObjectProxy made reference to a collection ArrayCollection, or a single object? Thank you very much in advance!

    Found an answer here:
    ons-in-adobe-flex-2-how-to-successfully-read-any-number-of-xml-nodes.aspx http://www.theruntime.com/blogs/be-sharp/archive/2008/02/26/Web-services-and-arraycollecti

    which provides a response if there are NO child nodes, if there is exactly one child node, or if there are several children nodes...

  • NEED HELP as soon as possible - the ArrayCollection collection analysis

    Hi all

    My web service returns a collection of table as follows with the following columns: name, ID, power, time.

    An example of the full collection would be: name Power Hour

    Texas                 5                    6

    New York 6.4 6

    2.1 the California 6

    Texas                 5.1                 7

    New York 6.5 7

    2.6 California 7

    I wish that my histogram of having another series for each different name so they would side Side(x axis = hour, y axis = power), now my problem is that I can't link the original collection of table to a chart I want.  So I need to change the table something like this:(I think)

    Time New York California Texas

    6          5          6.4                    2.1

    7          5.1       6.5                   2.6

    any help is greatly appreciated! Code... even more! Thank you guys!

    Yes, that's my bad.

    After looking a little closer to the example, it seems you need actually a series for each value of time, not each SiteName. You also composed the data in objects with a property name for each time value. Unfortunately, each category axis would be evenly size a SiteName with only 2 values would be the same size as the one with 10 different values. I did, however, this small example that uses stacked columns sort of you show how the series is implemented. If this does not work for you, you will have googled around to see how you can make a desabscisses with dynamic widths axis.

    
    http://ns.adobe.com/mxml/2009" xmlns:mx="library://ns.adobe.com/flex/mx"
                      xmlns:s="library://ns.adobe.com/flex/spark" height="100%" width="100%"
                      creationComplete="creationCompleteHandler(event)" >
    
         
              
         
    
         
    
         
    
         
    
              
    
                   
                        
                   
    
              
    
         
    
    
    
  • How to raise an event from the arrayCollection collection?

    I'm passing data from a model to a view in the following files. It works fine, but I want to send a message on the screen when an arrayCollection collection is filled. I know that I could create a custom event, but I do not understand why the eventhandler I created will not work. Please tell me what I'm doing wrong.

    Thank you.

    <? XML version = "1.0" encoding = "utf-8"? >
    " < = xmlns:mx mx:Application ' http://www.Adobe.com/2006/MXML "layout ="absolute"creationComplete =" init () "> "
    < mx:Script >
    <! [CDATA]
    Import mx.collections.ArrayCollection;
    Import mx.events.CollectionEvent;
    Import mx.rpc.events.ResultEvent;
    [Bindable] private var databaseDataArrayCollection:ArrayCollection = new ArrayCollection collection;
    [Bindable] private var: model = new modele();
    [Bindable] private var: controller = new Controller();
    private function init (): void {}
    model.databaseDataArrayCollection.addEventListener (CollectionEvent.COLLECTION_CHANGE, chan ge)
    model = Model.createInstance ();
    controller.getData ();
    }
    private void change(e:Event):void {}
    trace ("changed in sight")
    }
    []] >
    < / mx:Script >
    < mx:DataGrid dataProvider = "{model.databaseDataArrayCollection}" > "
    < mx:columns >
    < mx:DataGridColumn id = "first name" dataField = "first name" headerText = "FIRSTNAME" / >
    < mx:DataGridColumn id = "lastName" dataField = "lastName" headerText = "LAST NAME" / >
    < / mx:columns >
    < / mx:DataGrid >
    < / mx:Application >

    Model.As

    package {}
    Import mx.collections.ArrayCollection;
    [Bindable]
    public class {model
    public var databaseDataArrayCollection:ArrayCollection = new ArrayCollection();
    private static var: model = new model;
    private static var num:Number = 0;
    public void modele() {}
    }
    Public Shared function createInstance (): model {}
    NUM ++
    if(Model == null) {}
    model = new modele();
    }
    return the template;
    }
    }
    }

    Controller.As

    package {}
    import com.simon.cms.UrlString;

    import flash.events.Event;

    Import mx.collections.ArrayCollection;
    Import mx.events.CollectionEvent;
    Import mx.rpc.events.ResultEvent;
    Import mx.rpc.http.HTTPService;
    Import mx.utils.StringUtil;

    [Bindable]
    public class {controller
    private var: model = new modele();
    public var httpService:HTTPService = new HTTPService;
    private var login_string:UrlString = new UrlString();
    public void Controller() {}
    model = Model.createInstance ();
    }
    public void getData (): void {}
    var params: Object = new Object();
    httpService.url = login_string.login;
    httpService.method = "GET";
    httpService.addEventListener (ResultEvent.RESULT, extractData);
    httpService.send (params)
    }
    private void extractData(event:ResultEvent):void {}
    httpService.removeEventListener (ResultEvent.RESULT, extractData);
    model.databaseDataArrayCollection.addEventListener (CollectionEvent.COLLECTION_CHANGE, chan ge)
    model.databaseDataArrayCollection = event.result.student.task;
    }
    private void change(e:CollectionEvent):void {}
    trace ("Changed in the collection")
    }
    }
    }

    You use "=" this is a reversal/replacement.  There is no chip

    assignment that will update.

    You could do

    model.databaseDataArrayCollection.source =

    Event.Result.Student.Task.source;

    That should translate into a CollectionEventKind.RESET in original HQ as it

    now a new set of data.

Maybe you are looking for