6 Replies Latest reply on May 26, 2011 8:04 AM by miguel8312

    Random data into an arrayList into List

    Pisti123 Level 1

      Hi,

       

      During a certain project i'm doing, i need to insert random data into an arrayList that is used as dataProvider for a List.

       

      I'm using math.random() in order to get a random number between 0 - 3.

      After i get the random number i'm inserting it into the place where the arrayList is currently at.

      I must enter the data TWICE, no more and no less, must be twice.

      Later on the random numbers range will increase obviously.

      Once i run the application this is what i get:

      Error #1069: Property 0 not found on mx.collections.ArrayList and there is no default value.

       

      Programm: Flash builder 4.5

      AS3

       

      Any ideas? i'm pretty frustrated here

       

      Thanks in advance, Sagi.

        • 1. Re: Random data into an arrayList into List
          miguel8312 Level 3

          can you post some code its hard to see what your saying without code.

          miguel

          • 2. Re: Random data into an arrayList into List
            Pisti123 Level 1

            Hi,

             

            {
                            var _pairLimit:uint = (myLevelCounter * 2);
                            for (var i:uint = 0 ; i < _pairLimit ; i++)
                            {
                                var _myObject:Object;
                                var _myRandomNumber:uint = (myLevelCounter);
                                _myObject = _myRandomNumber;
                               
                                valueArray.addItem(_myObject);
                            }
                           
                            _cardsList.dataProvider = valueArray;

            }

             

            That's the function so far, solved the problem of getting the error #1069

             

            but still can't insert the stuff i want - twice (haven't figured that out yet), so any helpful tips would be most welcome!

            • 3. Re: Random data into an arrayList into List
              miguel8312 Level 3

              ok give me a few minutes let me try on my end.

              Miguel

              • 4. Re: Random data into an arrayList into List
                miguel8312 Level 3

                is this what you are looking for

                 

                 

                 

                <?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" 
                      xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                      applicationComplete="addItemsToList()">
                 <fx:Declarations>
                  <!-- Place non-visual elements (e.g., services, value objects) here -->
                 </fx:Declarations>
                <fx:Script>
                 <![CDATA[
                  import mx.collections.ArrayList;
                  private var arrLst : ArrayList = new ArrayList;
                  
                  
                  public function addItemsToList():void{
                   var myLevelCounter : int = 1;
                   var _pairLimit:uint = (myLevelCounter * 2);
                   var num : Number
                   for (var i:uint = 0 ; i < 3 ; i++)
                   {
                   
                    num =Math.round(Math.random()*3);
                   trace(num);
                   arrLst.addItem({"RANDOM NUMBER" : num});
                    
                   
                   trace (arrLst.toString());
                   
                   
                   
                   }
                   
                  
                  
                  
                  
                  
                  }
                  
                  
                 ]]>
                </fx:Script>
                
                
                
                
                
                </s:Application>
                
                1 person found this helpful
                • 5. Re: Random data into an arrayList into List
                  miguel8312 Level 3

                  by the way i realize this line is going to return [object] [object] if you assign to a grid

                  youll be ok but if you want to actually see the values you are going to have to loop through those again.

                  and display.

                  Miguel

                  • 6. Re: Random data into an arrayList into List
                    Pisti123 Level 1

                    Actually it is, gave me a good direction, thank you very much!