This page was last modified 10:20, 26 April 2008.
Simulating Arrays in better way in Flash Lite 1.1
From Forum Nokia Wiki
Flash Lite 1.1
Contents |
Introduction
Even though the latest version of Flash Lite supports arrays, the market is already populated with devices supporting Flash Lite 1.1. 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.
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 an example with source code here: CodeExampleSimulatingArray
| Related Discussions | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Video streaming in flash lite | vinaykk | Flash Lite on Nokia Devices | 3 | 2008-02-11 13:11 |
| How to make a Flash screensaver? | MobileVisuals | Flash Lite on Nokia Devices | 4 | 2008-01-03 13:35 |
| Is possible to insert Flash Lite content inside Symbian Container | fjorge_ht | Flash Lite on Nokia Devices | 5 | 2007-12-01 21:49 |
| What happened with animoi??? | Pepper_91 | Mobile Java Media (Graphics & Sounds) | 4 | 2006-10-09 09:48 |
| Browser tosses unknown mimetypes? | cypher181 | General Symbian C++ | 5 | 2006-11-30 19:52 |
