开发者

Retrieve Objects Item information from ArrayCollection???

开发者 https://www.devze.com 2023-03-31 04:40 出处:网络
I am currently using the latest verion of Adobe Flash Builder to create a Mobile Application. For the application one feature is to allow the users to bookmark content an this is done by storing the i

I am currently using the latest verion of Adobe Flash Builder to create a Mobile Application. For the application one feature is to allow the users to bookmark content an this is done by storing the id of the object to be Bookmarked into an SQLite db on the device. This part has been done successfully and they are stored fine.

Now what I want to do is to pull back the bookmarked id's from the database and pass them to a WebService call which needs to be made to an External Database. When I retrieve the Bookmark id's from the local database they are contained within object, I now need to find a way to take the id's from the database objects in the ArrayCollection and store them in a new array that will be passed to the WebService, as the webservice is expecting an Array of Int's and not Objects. Below is the code I created to see if the object items are within the array list of objects:

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

Now when I test the app all seems fine and the trace statement returns the following:

Element 0 is 91
Element 1 is 9
Element 2 is 9
Element 3 is 9
Element 4 is 9
Element 5 is 9
Element 6 is 9
Element 7 is 282
Element 8 is 282
Elem开发者_如何学运维ent 9 is 282
Element 10 is 282
Element 11 is 282
Element 12 is 282

However I then tried to populate the Int values for each of the objects into a new array using the code below:

var ids:Array;
                var index:int;
                for( index = 0; index < compsCollection.length; index++ )
                {
                    trace( "Element " + index + " is " + compsCollection[index].comp_id );
                    ids.push(compsCollection[index].comp_id);
                }               
            }

However when I run this code I get this error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.

This error occurs on line:

ids.push(compsCollection[index].comp_id);

I do not understand why i am getting this error, can anyone please help?? Thanks


While I don't know anything about Adobe Flash Builder, generally you have to instantiate an array before using it.

var ids:Array = []; 

maybe?? (As RIAstar suggested)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号