PDA

View Full Version : desperately trying to learn arrays -HELP !



SteveD
April 28th, 2003, 10:08 AM
Hi,
I have been helping out a few members here with arrays in an effort to finally get my head around them. I think that arrays are probably one of the more powerful tools available in flash, but...... I got myself stuck and need some help. I feel sure it just a syntax issue. here goes:

mc with instance name but0
inside mc is a text box var name label , code is
label = _name;

mc on main timeline code in frame 1 is:

subjects = new Array("page1","page2","page4","page4","page5")
butHeight = but0._height+5;
butNumber = subjects.length
if (i<butNumber) {
but0.duplicateMovieClip("subjects"+i,i);
with(this["subjects"+i]) {
_y= butHeight*i;
}
i++
}
but0._visible = 0;

What this code does is produce 5 buttons appearing one after the other, like a cascade effect, so far so good, I then want to insert the array elements into text box label, but all I get is subject, subject1, subject2 and so on.
So, what do I need to do so that my buttons are called page1, page2 and so on.

Cheers

SteveD

kode
April 28th, 2003, 10:40 AM
change this line

but0.duplicateMovieClip("subjects"+i, i);
to

but0.duplicateMovieClip(subjects[Number(i)], i);
... =)

SteveD
April 28th, 2003, 10:57 AM
Thanks kax
But sort of, not quite, I get an error message, with action failed etc etc, but the one button that does appear has "page5" in it, think they are duplicating OK but not spacing out. ?
I'll keep trying, any other ideas welcome

Cheers

SteveD

kode
April 28th, 2003, 11:02 AM
did you change this line as well?

with (this["subjects"+i]) {
it should be

with (this[subjects[Number(i)]]) {
that's all i can think of... :-\

SteveD
April 28th, 2003, 11:26 AM
Hi,
again, not quite, this time the buttons are cascading, but something is awry with the order - I have posted my fla if you ( or anyone else) has the time to take a quick peek

Cheers

SteveD

SteveD
April 28th, 2003, 11:46 AM
Hi kax,
Solved it, there was a typo in the array, everything working OK now, thanks for your help
Cheers

SteveD

kode
April 28th, 2003, 11:50 AM
:P

yeah... usually the easy problems are the hardest to solve. :-\