I’m having problems adding elements to arrays but for some reason the array looses the elements when the function that adds the new elements goes out of scope (I’m coming from a c# and VB background so excuse some terminology).
For example I have the following class:
Code:
class Classes. Data_Store
{
var dataStore:Object = new Object();
function Data_Store()
{
//Constructor
}
//*******************
//New DataStore
//*******************
function newDataStore()
{
dataStore.DataStore = new Object();
dataStore.DataStore.dataRow = new Array();
}
}
In another class I have the following class that contains code that use the Data_Store and the newDataStore function within it to populate an array and then add a new element to the original array – Computer say no when I try access the new element of the array by returning “undefined”:
Code:
Class Classes.Use_DataStore
{
function Use_DataStore()
{
//Constructor
}
Function loadData(recordID)
{
var myService:Service = new Service(_level0.serverType, null, _level0.cfComponentPath, null, null);
var pc:PendingCall = myService.loadData({recordID});
pc.responder = new RelayResponder(this, “loadData_Result”, “loadData_Error”);
}
Function loadData_Result(res:ResultEvent)
{
// Create new data store object
_root.Data_Store.newDataStore();
// Load data into dataStore array – code omitted as not relevant
// Add new elements to array
addElementsToArray();
// Loop through array hopefully with new element attached
for (var prop in _root.Data_Store.dataStore.dataRow
}
function loadData_Error()
{
_level0.Message.drawInfo(“loadData_Error”);
}
function addElementsToArray()
{
for (var i = 0; i < _root.Data_Store.dataStore.DataStore.dataRow.length; i++)
{
_root.Data_Store.dataStore.DataStore.dataRow.myNewElement = “Element” + i;
}
}
}
Bookmarks