Singleton empty ArrayCollection in Flashbuilder (Mobile) collection class?

Hello

I am currently trying to implememnt a Singleton class to store a collection of ArrayCollection of items that I can then access and manipulate through the lifecycle of my application. I created the Sub Singleton class that is designed to receive the ArrayCollection collection information:

package valueObjects
{
    import mx.collections.ArrayCollection;    
    
    [Bindable]
    public class Model
    {
        private static var instance:Model = new Model();
        
        public var ids:ArrayCollection = new ArrayCollection();
                                
        public function Model()
        {
            if(instance)
            {
                trace("New instance cannot be created. Use Singleton.getInstance()");
            }
        }
        
        public static function getInstance():Model
        {
            return instance;
        }
    }
}

I then created the following code on the main page Deafult to my request so that the ArrayCollection collection is filled as soon as the application is launched:

            import valueObjects.Model;            
            
            protected var models:Model = new Model();

                        private function loop():void
            {
                var index:int;
                for( index = 0; index < compsCollection.length; index++ )
                {
                    trace( "Element " + index + " is " +  compsCollection[index].comp_id );
                                models.ids.addItem(compsCollection[index].comp_id);
                    trace(models.ids.length);
                }                
            }

The ArrayCollection collection in the Singleton class is filled as the trace instruction that I entered the loop clearly shows the generation of data in the ArrayCollection collection. But then when I move to another view of the application I then try to access this ArrayCollection collection within the Singleton class with the following code:

import valueObjects.Model;

protected var models:Model = Model.getInstance();
protected var test:ArrayCollection = new ArrayCollection();

protected function view1_viewActivateHandler(event:ViewNavigatorEvent):void
            {
                
                var index:int;
                trace("Array Length =" + models.ids.length);
                for( index = 0; index < models.ids.length; index++ )
                {
                    trace( "Element " + index + " is " + models.ids[index].comp_id );
                    test.addItem(models.ids[index].comp_id);
                }    
                testbox.text = test.toString();
            }

Now the problem I have is that when I try to access this ArrayCollection (ids), it seems to be empty for some reason any. I've included a trace statement that also indicates that the length of the ArrayCollection collection is '0 '. Can someone please help?

If your value object class changes that

change this

public var ID: collection ArrayCollection = new ArrayCollection();
TO

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

on your default page to change it

models.ids.addItem (compsCollection [index] .comp_id);

TO

valueObjects.Model.ids.addItem(compsCollection[index].comp_id);

on your display something like that change.

protected

 function view1_viewActivateHandler():void
          {
               //initialize="view1_viewActivateHandler();"
               var index:int;
               trace("Array Length =" + valueObjects.Model.ids.length);
               for( index = 0; index < valueObjects.Model.ids.length; index++ )
               {
                    trace( "Element " + index + " is " + valueObjects.Model.ids[index].comp_id );
                    test.addItem(valueObjects.Model.ids[index].comp_id);
               }
               //testbox.text = test.toString();
          }

good luck let me know if you have any questions I have tested it and it worked like a charm for me.

Miguel

Tags: Flex

Similar Questions

  • I'm trying to synchronize my mobile collection to lightroom but it keeps saying waiting for connection

    Hello

    I'm trying to synchronize my mobile collection to lightroom but it keeps saying pending connection. any thoughts?

    We have identified the root cause of the sync problem that will be fixed with the next update of the Office from Lr. In the meantime, the only solution for you is to downgrade to the previous version of Lr. sorry for the inconvenience (via the CC - app). Guido

  • How to get the Type of a Collection class

    Hi all
    I just want to ask if there is a simple way to get the type of a Collection class.

    For example, for an ArrayList < String > or items of list < number > integer, dynamically how 'String' or 'Integer' class object (expecially with generic types) without any sequences of strange reflections?

    Thank you!

    Java generics follow one main erasure called which essentially States that any generic info is maintained during execution. If you can not, even if you can get information about variables and fields of reflection.

  • Strange behavior on DataGrid with ArrayCollection as a DataProvider collection

    I have a Datagrid with an ArrayCollection as a DataProvider collection, the arrayCollection collection is partially generated by a remoteObject call, the dataprovider seems to work at least until I try to change the field...

    By the RemoteObject, I get only a collection ArrayCollection with the 'ip' field, but the data grid seeks ip, check and recordfields...

    If I add/edit this field new it works, but only under specific condition

    The DataGrid control:

     <s:DataGrid id="datagrid" left="10" right="10" top="136" 
           dataProvider="{listaIPCheck}" bottom="10" requestedRowCount="4">
              <s:columns>
                    <s:ArrayList>
                         <s:GridColumn dataField="ip" headerText="Asset"/>
                         <s:GridColumn dataField="check" headerText="Inventory"/>
                         <s:GridColumn dataField="save" headerText="Salvataggio"/>
                    </s:ArrayList>
               </s:columns>
     </s:DataGrid>
    

    The Script:

       [Bindable]private var listaIPCheck:ArrayCollection; 
    
        private function ro_resultHandler(event:Event=null):void
        {
          listaIPCheck = new ArrayCollection();
          listaIPCheck = ro.getListUpdate.lastResult;
          heap = 0; 
          // Read Below {POINT #1}
          init3(); 
        }
    
    
        private function init3():void
        {
         // Read Below {POINT #2}
         if (heap<listaIPCheck.length)
         {
            // omitted the initialization of the process p
            p.addEventListener(NativeProcessExitEvent.EXIT, onExit);
            try{ 
              p.start(startupInfo);
            }catch(e:Error){}
         }
        }
    
    
    
        private function onExit(e:NativeProcessExitEvent):void { 
            // Read below {POINT #3}
        }
    

    Here is my code, now, as you can see there are 3 lines where I wrote to read below...

    Suppose that to put this simple 'for' instead of the commented (once both) line

        for (var k:Number=0;k<listaIPCheck.length;k++)
        {
          listaIPCheck.getItemAt(k).check = "checkVal";
          listaIPCheck.getItemAt(k).save = "saveVal";
        }
    

    This code still works in 3 points, so at the end of the call, the ArrayCollection collection is always filled with new values, but the datagrid control refresh the items only in the POINT #1 and #2 of POINT

    Why not the Point #3?

    When you get a large number of items in your list, you will probably also find it resets the selectedIndex property and jumps on the first line of data.  It is not automatically updated because the ArrayCollection collection look inside objects to see if they change.  When they change, you must indicate the ArrayCollection collection they changed, call itemUpdated.

  • Fill() return empty ArrayCollection collection

    Hello

    I'm new to SDS and do not know why the fill() method returns nothing, even if the assembler returns a list of 3 items. I know the list is back nothing because when I see the length of the ArrayConnection, it is 0.

    I'm Tournai on the debugging logs and see the 3 items returned. Do you have tips on how I can solve this problem?

    Is there somewhere in the configuration where I specify the Java class maps to ActionScript class B? I just deleted my corresponding ActionScript class and always the same newspapers. I suspect that the SDS does not know how to map the Java class in the ActionScript class so that it gives me an empty list and throws the results. Does this sound right? If there is some sort of automatic mapping, I was expecting to see an error in the log after I deleted the ActionScript class.

    Thank you
    Jamie

    [Flex] 18/05/2007 12:19:31.443 [DEBUG] [DataService.Transaction] committed trans
    action
    [Flex] 18/05/2007 12:19:31.443 [DEBUG] [Message.Data.fill] after calling a service:
    data service
    answer: Flex Message (flex.data.messages.SequencedMessage)
    sequenceId = 0
    sequenceSize = 3
    (no proxy sequence)
    clientId = null
    correlationId = null
    destination = company
    messageId = 7A2A0D8F-C32B-80BC-D593-4551B71320F1
    timestamp = 1179515971443
    timeToLive = 0
    body =
    [
    Company (companyId = 100, name = null, address = null, status = null, zip = null undue
    Try = null),
    Company (companyId = 101, name = null, address = null, status = null, zip = null undue
    Try = null),
    Company (companyId = 102, name = null, address = null, status = null, zip = null undue
    Try = null)
    ]

    I found the answer to my own question. It was just a race condition. You can not read the size of the ArrayCollection collection immediately. The list takes some time to complete.

  • Decree of mobile collections Lightroom is not sync

    I created a collection that I am with the LR Mobile synchronization.  I reorganized a few photos in the collection, but it does not appear that the synchronization of photos of the mobile application, would reach this sequencing.  Is this something that could be coming on the road in an update?

    It is not yet supported for the Mobile with Lightroom version. It is coming soon.

  • Flex 4.6 for mobile, mx classes seem to be missing. (in my case the Repeater)

    Hello, I just started with Flex 4.6 for mobile.
    I was reading that flex for mobile has been improved for performance on mobile.
    If this update, they removed the mx classes? For exmple I wanted to try this tutorial:

    (using a Repeater)

    http://help.Adobe.com/en_US/Flex/using/WS2db454920e96a9e51e63e3d11c0bf6443d-7ffc.html

    But it seems that I am getting the error could not resolve < mx:Repeater > and it should be in mx.core but I can't
    found anywhere.  I also tried different namespaces in my mxml as:

    ' xmlns:mx = ' http://www.Adobe.com/2006/MXML "or xmlns:controls =" mx.core. * "" or xmlns:mx = "library://ns.adobe.com/flex/mx"

    I don't have all the results in this way.  Does anyone have an idea how to get access to the Repeater class? Also, Miss me the

    MX of dataProvider class.

    Kind regards

    Chris

    That is right.  Only Spark components are optimized for mobile devices and have touch support.

  • Flex ArrayCollection for Java HashSet collection

    Hello


    I got a problem I can't solve by googleing. I need your expertise:

    The part of the story (s) here:

    1 Bdc have much BdcDetails, both in Flex Bdc.as == > public var bdcdetails:ArrayCollection; in Java Bdc.java == > private Set < BdcDetails > bdcdetails = new HashSet < BdcDetails > ();

    It works perfectly in Flex which means Flex understand what is inside a Java HashSet. But when a Bdc is sent to Java. Java do not understand what is inside the ArrayCollection collection, everything is ASObject.     Yes ((BdcDetails) bdc.getBdcdetails () .toArray () [0]) == > give ClassCastException

    Help, please! Thank you

    P/S: I'm using Blaze DS 4.5.0.0 - SNAPSHOT

    Thanks, I ve found work around it.

    I have create a setter for Bdc.as

    bdcDetails in which I have to loop through the collection of arraycollection, mount the funtion value

    BdcDetails of each element is then returned to the arraycollection collection.

    That s it. I don't know it is good or not, but it works

  • Bookmark profile on empty office, cannot sync mobile

    I got the MixiDJ research/toolbar malware on my desk with tracks in windows 7. I deleted the program from the Control Panel, but she came back. After reading a lot of info forum, I ended up resetting Firefox but... they do not mention that you need to back up your bookmarks. I checked the profile folder and it is empty. My Samsung phone was synchronised to they have disappeared there. My Kindle Fire, however, shows all of my favorites intact and only the following folders show as "Synchronized" for Firefox on KFTT: subject: blank and a crochet site.

    I tried to synchronize completely, but I don't get the synchronization code when I try to add the device to my desktop. I don't have the popup of the Synchronization Manager. When I opened the settings, I get a tab sync but it shows just the 2 tabs listed above.

    Help!

    It should have probably been enough reset preferences if MixiDJ been deleted programs.

    You have an "Old data Firefox" folder on the desktop?

    If you have you should find backups JSON (bookmarks-#-#-.json #) in the folder bookmarkbackups.

    When you reset Firefox and a new profile is created and some personal data (bookmarks, history, cookies, passwords, data form) are automatically imported and the current profile folder will be moved on the desktop (old data of Firefox).
    You will lose the extensions and other customizations (toolbars, Pref.) that you have made.

    It is possible to recover more data from the old profile, but be careful not to copy the files corrupted to avoid transporting on the problem.

  • Collection ArrayCollection in flex and ArrayList in java




    Salvation of this world don't
    Here I am with my problem with the hope someone can solve it
    I am totally new to flex and I work only for 3 days in flex. and I learned a little more.
    I want to get the values of database that is received from java to flex datagrid object by using the data provider.
    I did quite well in my opinion. But I could not produce the result in the data grid. Since I am very new. I don't know what is happening.

    my code is here, please help me.

    My mxml file: Myadmin.mxml

    <? XML version = "1.0" encoding = "utf-8"? >
    "" < mx:Application xmlns:mx = ' http://www.adobe.com/2006/mxml ' layout = "vertical" >
    < mx:RemoteObject id = "ber" destination = "dock" showBusyCursor = "true" fault = "faultHandler (event)" > "
    < name mx:method = "getBerth" result = "resultHandler (event)" / >
    < / mx:RemoteObject >

    < mx:Panel id = 'Top' title = "MaBase" width = "100%" height = "40%" enabled = "true" >
    < mx:TextArea id = "sql" width = "100%" height="100%"/ >

    < mx:Button label = "Execute" click = "handleSend ()" / >

    < / mx:Panel >

    < mx:Panel id = "bottomPanel" title = "Results" width = "100%" height = "60%" enabled = "true" >
    < mx:DataGrid id = "dg" dataProvider = "{result}" width = "100 percent" height="100%"/ >


    < / mx:Panel >
    < mx:Label id = "resultLabel" text = "Onumae puriyale ulgathulae" / >

    < mx:Script >
    <! [CDATA]

    Mx.rpc.events import. *;
    Import mx.collections. *;
    Mx.controls import. *;
    Import mx.utils.ObjectUtil;




    caching empty ArrayCollection collection so that we don't continue to create
    new

    private var emptyResults:ArrayCollection = new ArrayCollection();

    [Bindable]
    public var result: ArrayCollection collection = emptyResults;







    private void resultHandler(event:ResultEvent):void
    {
    Alert.Show ("event.result table of results", ObjectUtil.toString (event.result as ArrayCollection collection));
    result = ArrayCollection (event.result);
    var myCursor:IViewCursor=result.createCursor();
    var oldLength:int = result.length;

    Alert.Show (oldLength.ToString ());




    }

    private void faultHandler(event:FaultEvent):void
    {
    Alert.Show (event.fault.faultString, "Error");
    }

    private function handleSend (): void
    {


    ber.getBerth ();


    }




    []] >
    < / mx:Script >


    < / mx:Application >

    My java object: Berth.java


    package samples.sqladmin;
    import java.sql. *;
    Import Java.util;
    import java. IO;

    public class Berth

    {
    Public Shared Sub main (String args []) throws exceptions
    {
    List ArrayList = getBerth();
    System.out.println ("the list is =" + list);
    }

    public static ArrayList getBerth () throws Exception {}
    Connection con = null;
    Statement st = null;
    ResultSet rs = null;
    ResultSetMetaData rsmd = null;
    List ArrayList = new ArrayList();
    HashMap line = null;
    try {}
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    } catch (ClassNotFoundException nctf) {}
    System.out.println (CNFE.getMessage ());
    }
    try {}
    con = DriverManager.getConnection ("jdbc:odbc:Jurong", "","");
    St = con.createStatement ();
    String sql = "select * berth;
    RS = ST. ExecuteQuery (SQL);
    rsmd = rs.getMetaData ();
    int colCount = rsmd.getColumnCount ();
    While (RS. Next {}
    line = new HashMap();
    for (int i = 1; i < = colCount; i ++) {}
    Row.put (rsmd. GetColumnName (i), rs.getString (i));
    }
    List.Add (Row);
    }

    }
    {} catch (SQLException sqle)
    System.out.println ("enna da yogans eeeeee...");
    System.out.println (sqle.getMessage ());
    }

    If (con! = null)
    con. Close;
    If (st! = null)
    St.Close ();
    back list;

    }

    }

    my remote-config file is:

    < destination id = "dock" >
    Properties of <>
    samples.sqladmin.Berth < source > < / source >
    < / properties >
    < / destination >

    I got the table in flex collection object, but it gives the values received in java

    Please help me.
    Thanks in advance
    yogans.

    Hi my dear friends

    I'm sorry to put you in trouble. I got the result. The problem is
    not with the code. its with my system. The problem is that I have configured
    same name for datesource for system and user DSN DSN name. After that I deleted
    a user DSN data source. I got it working.

    Thank you very much william, thank you much Nelson for your spontaneous response

    Thank you
    Yogans

  • Do not have a collection "From Lr mobile" but OK synchronization between mobile devices

    Hello

    I tried to synchronize my mobile devices with Lightroom desktop 6.3. Put a few photos in a collection synchronized on my tablet. Works correctly between my iphone 5 s and my Sony tablet, but...

    -I do not see any mobile 'From Lr' collection folder on desktop with Lightroom.

    -Clear the "cache" in mobile Lightroom Lightroom desktop preferences clear my collection on mobile devices!

    Maybe I deleted the mobile collection of"Lr" folder?

    Thanks for your help

    Alain

    Uninstalled and compensated Lightroom 6.3 prefs.

    Re-installed Lr6.3, Lr Mobile files and collections appeared, Hooray!

    Open my old catalogue, collections and folders mobile Lr disappeared! GRRRR...

    Import my big catalogue in a new...

    Thanks for the help

  • Singleton class Vs static

    Hello

    Please excuse if my question annoys someone in the forum.

    Compared to a singleton class we will always have a class and all static methods?

    That would be the same as Singleton.


    Also watching Runtime class is a Singleton. Just think if the runtime class might be a class with this static methods instead of making the constructor private.

    For me, the answer depends on the class has a State or not.

    If so, then I would use a singleton.
    If not, then I would do a class with all the static methods.

    (this private tor is selected in both cases)

  • return index collection ArrayCollection-1 after updating in datagrid

    When I called data.refresh ();  arraycollection.getItemIndex (obj1) returns-1

    is anyway to make it work properly or work around?

    <? 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"preinitialize ="application1_preinitializeHandler (event) ".

    xmlns:MX ="library://ns.adobe.com/flex/mx"minWidth = "955" = "600" xmlns:local = minHeight"*" > "

    < fx:Script >

    <! [CDATA]

    Import mx.collections.ArrayCollection;

    Import mx.collections.Sort;

    Import mx.events.FlexEvent;

    private var data: ArrayCollection collection;

    private var obj1:Object;

    protected function application1_preinitializeHandler(event:FlexEvent):void

    {

    obj1 = {'name': '1'}

    data = new ArrayCollection();

    data.addItem (obj1);

    data.addItem({"name":"2"});)

    trace (Data.GetItemIndex (obj1)); 0

    var sort: sort = new Sort();

    sort.compareFunction = nameSort;

    Data.sort = sort;

    data .filterFunction = null;

    Data.Refresh ();

    -1 trace (Data.GetItemIndex (obj1))

    }

    private void aa (): void {}

    }

    private void nameSort(m1:Object,_m2:Object,arr:Array=null):int {}

    Returns - 1;

    }

    []] >

    < / fx:Script >

    < fx:Declarations >

    < / fx:Declarations >

    < / s:Application >

    A comparison function sorts must return 1, 0 or - 1 on a consistent basis.  He

    cannot simply return-1.

  • What is the need to sort an ArrayCollection collection?

    Hello

    But can you get it someone please let me know why there is easy sort of the ArrayCollection collection?

    Where this might be useful? because insofar as my collection ArrayCollection knowledge would be used as a dataprovider to a DataGrid and datagrid already has a facility for sorting according to the column header clcik.

    So why or where Mecahnism type is used in the ArrayCollection collection?


    Please apologize if the question is stupid.

    Please share your ideas.

    In fact, the DataGrid type use sorting the Collection, she uses as a dataProvider, which means that the type of collection ArrayCollection is used if the dataProvider is an ArrayCollection collection.

    It can also be useful when you need to process an ArrayCollection of the elements collection in a particular order. Sorting the collection ArrayCollection using a for each loop to process the data in the correct order.

  • Iterate multidimensional ArrayCollections

    Hello

    I'm doing a class that would transform an arrayCollection in the XML collection. I want to make it useful for all ArrayCollections.

    My arraycollection collection looks like this...

                        newsDB.addItem( { 
                             title: titleText.label, 
                             clickURL: clickURL.text, 
                             info: itemInfo.text, 
                             abstract: abstract.text, 
                             category: category.selectedLabel, 
                             rateItem: rateItem.selectedIndex 
                        });
    

    My class looks like this.

    package com.ryancanulla.utils
    {
         import mx.collections.ArrayCollection;
         
         public class ArrayCollectionToXml
         {
              private var dataSource:ArrayCollection = new ArrayCollection;
              
              public function ArrayCollectionToXml(array:ArrayCollection):void {
                   dataSource = array as ArrayCollection;
                   
                   trace(dataSource[0]);
                   
                   for(var i:int=0; i<dataSource.length; i++){
                        
                   }
              
              }
    
         }
    }
    

    I can access the AC with a loop and arrayCollection.length, but how to I go further in HQ in so doing works for entire collection ArrayCollection? I could easily make dataSource [i] .title but want to make this work for all arrayCollection collection passed into the class.

    Thanks in advance for any help!

    data source is an array of objects.  You can browse objects by using a loop of component snap.

    Use the trace() function to see what is happening:

    for (var s:String in {dataSource [i])}

    trace (s, DataSource [i] [s]);

    }

Maybe you are looking for