Archived:Simulating Arrays in better way in Flash Lite 1.1
We do not recommend Flash Lite development on current Nokia devices, and all Flash Lite articles on this wiki have been archived. Flash Lite has been removed from all Nokia Asha and recent Series 40 devices and has limited support on Symbian. Specific information for Nokia Belle is available in Flash Lite on Nokia Browser for Symbian. Specific information for OLD Series 40 and Symbian devices is available in the Flash Lite Developers Library.
Article Metadata
Code Example
Article
Contents |
Introduction
Even though the latest version of Flash Lite supports arrays, the market is already populated with devices supporting Flash Lite 1.1 only. And Flash Lite 1.1 does not support arrays. So when designing the Flash Lite application, target device plays a vital role. There is traditional approach to simulate arrays by creating a bunch of variables and accessing them using ‘eval’. This approach is memory consuming and a bit odd to use. So we can simulate the array in a better way as follows.
Source Code
Define Length of each item in array
Define the length of each item in the array. Make sure to mention each individual item with 'counter' numbers/characters.
counter = 2; //This is the length of each item.
Eg.: If counter is set to 2, the elements will be 01,02,03. If counter is set to 3, the elements will be 001,002,003.
Define Array
Define the array as a string and individual items of the array in the sequence. Add the ‘&&’ character at the end of the string as a delimiter.
option_0 = "010203040607081213141516171819202122242526272829303132&&";Here the elements are 01,02,03 as counter is set to 2.
Define 'fnGetLength' Function
Define a ‘FunctionClip’ named ‘mcFunction’ and add the following code in the frame labeled as ‘fnGetLength’. This function will return the length of the array.
nLength = 0;
start_ind = 1;
//Set the starting index as 1 always
str = "a";
//Define the str to any value for initilisation
while (str ne "&&") {
str = substring(_parent.option_0, start_ind, _parent.counter);
start_ind = start_ind+_parent.counter;
if (str != 0) {
nLength = nLength+1;
}
}
//The above while loop will iterate through the array option_0'.The 'substring'
//function will return the array element as we give the offset and the length of
//the individual element. The loop will iterate till it encounters a 'Delimiter'.
trace("Length Of Array is:: "+nLength);
On the main timeline you can access this function as follows:
call("mcFunction:fnGetLength");
Define 'fnGetElementbyIndex' Function
In the same ‘FunctionClip’ named ‘mcFunction’ add the following code in the frame labeled as ‘fnGetElementbyIndex’. This function will return the element of the array, given the item index as ‘nElementIndex’.
nStartIndex = (_parent.nElementIndex*Number(_parent.counter))+1;
//Depending upon the element to access the offset will be calculted
str = substring(_parent.option_0, nStartIndex, _parent.counter);
trace("ELEMENT:: "+str);
On the main timeline you can access this function as follows:
First set the index number required
nElementIndex = 0;
call("mcFunction:fnGetElementbyIndex")
Download
You can download the source code at Simulating Arrays in Flash Lite 1.1.


(no comments yet)