Wednesday, 20 June 2007

Using Arrays? (FL1.1)

Can I create an array in Flash Lite 1.1?

Unfortunately they are not supported. This has been a common question, as it is definitely an important component in creating icon menus as it drastically simplifies the process. However, what you can do is create a pseudo-array where you name variables using actionscript and a counter, like so:

This will set the variable 'numbers1' equal to one:
eval("numbers1") = 1;

This will set the variable 'numbers2" equal to two:
eval("numbers" add 2) = 2;

If you want to create the range of variables "numbers1" to "numbers9", then you simply do the following:

for(i==1; i<10; i++){
eval("numbers" add i) = i;

Here is an application of using this method:

For a typical SE flash menu with icon scrolling, you will have a movieclip that contains each of the 12 icons in each frame. There will be a stop() command on frame 1 to keep it from playing. You will place 5 of the same movieclips on stage, and give them instance names icon0, icon1, icon2, icon3 and icon4. Now, if you want to designate which icon they want to show, you can easily accomplish this through a for loop :

tellTarget("icon" add /:x){

I found this method particularly useful in designating and changing icons in flash lite menus.

No comments: