Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Array items won't persist

Status
Not open for further replies.

wagtail

Programmer
Feb 11, 2002
3
GB
Hi,

I have a Flash movie with two simple buttons.

Clicking button A adds some test data to an array called "list" and dumps it to the Output window. This
works fine. I can see the data.

Clicking button B simply dumps the array to Output so I can inspect it. However, whenever I click B, the array is always empty.

The code looks like this:

On frame 1 of the main timeline, I place the following script (in its own layer):

list = new Array();

function writeToList()
{
list.push("joe");
list.push("anne");
list.push("fred");
}

function dumpList()
{
trace("the list contains " + list.length + " items");

var i;
for (i = 0; i < list.length; i++)
{
trace(&quot;item [&quot; + i + &quot;] = &quot; + list);
}
}

The script for button A is:

on (release)
{
writeToList();
dumpList();
}

The script for button B is:

on (release)
{
dumpList();
}

If I push values onto the array immediately after creating it (outwith the functions), they persist.
But any items I add interactively just vanish.

I've also tried initialising the array with a specified size, but still no luck.

Can anyone tell me how to get this to work?

Thanks.



 
Your code tested out fine for me!
Unless I'm missing something here!

Regards,
new.gif
 
Hi oldnewbie,

Thanks for your reasuring reply! Reassuring, but strange too, as it definitely doesn't work for me...

Could you possibly mail me the .fla that works for you, so I can try it here? I'll send you mine in hopes you could take a look at it.

It's 11pm here so I'm packing in for the night. Will check back tomorrow morning.

Thanks and regards,

wagtail
 
Either put a stop action on your first frame along with your functions, or make sure the layer holding the actions is as long as the others and that they're no blank keyframe like you have in your's.
With either method, your script works fine!

Regards,
new.gif
 
Works like a dream! Thanks oldnewbie.

I hadn't realised that Flash kept looping through the movie. It must have been constantly reinitialising my array and wiping out the items!

Thanks and regards,

wagtail
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top