Copy link to clipboard
Copied
Hey
I am creating several buttons using a for loop - about 100 buttons.
for (var i: int = 0, total: int = xmlLengde; i < total; i++) {
bgmList.push(myXML..Song.songURL)
button1 = new Favorite();
button1.name = "favorite" + i;
button1.mouseChildren = false;
button1.y = button.y + (button.height - button1.height) / 2;
button1.x = button.x + button.width - 10 + button1.width / 2;
container1.addChild(button1);
}
I have an array like this:// this is traced - FavoritterID: 5,6,1,2,13,88,73.
All the buttons are movieclips that has 2 frames.
What I want to do now is make favorite5, favorite6, favorite1 and so forth go to next frame.
I have tried this and a few other things. Doesnt seem to work.
for(var ii: int =0, ii<FavoritterID.length; ii++){
button1.nextFrame();
favorite+i.nextFrame();
}
thanks
oops, you don't have any objects with reference favorite0, favorite1 etc. those are all name properties. ie, use
for(var p: int =0; p<FavoritterID.length; p++){
MovieClip(container1.getChildByName('favorite'+p)).nextFrame();
}
Copy link to clipboard
Copied
use array notation to coerce strings to objects:
for (var i: int = 0, total: int = xmlLengde; i < total; i++) {
bgmList.push(myXML..Song.songURL)
button1 = new Favorite();
button1.name = "favorite" + i;
button1.mouseChildren = false;
button1.y = button.y + (button.height - button1.height) / 2;
button1.x = button.x + button.width - 10 + button1.width / 2;
container1.addChild(button1);
}
for(var ii: int =0; ii<FavoritterID.length; ii++){
this['favorite'+ii].nextFrame();
}
Copy link to clipboard
Copied
Fixing the use of "ii" as the iterator variable would also help. And the comma in the for loop instead of a semicolon.
Copy link to clipboard
Copied
Error #1010: A term is undefined and has no properties. at the line having this code: "this['favorite'+p].nextFrame();"
It didnt work, so I tried a few other things, which didnt work either.
for(var p: int =0; p<FavoritterID.length; p++){
//getChildByName("favorite" + p).nextFrame();
//container1.(this['favorite'+p]).nextFrame();
this['favorite'+p].nextFrame();
}
Copy link to clipboard
Copied
I was thinking it might had to do with the buttons being placed inside container1. But it didnt seem to change anything.
Copy link to clipboard
Copied
oliversen wrote
I was thinking it might had to do with the buttons being placed inside container1. But it didnt seem to change anything.
this.container["favorite" + p].nextFrame();
Copy link to clipboard
Copied
for(var p: int =0; p<FavoritterID.length; p++){
trace(FavoritterID);
trace(FavoritterID.length);
trace(p);
//this['favorite'+p].nextFrame();
this.container1['favorite'+FavoritterID
].nextFrame();
}
Result of traces:
5,6,1
3
0
TypeError: Error #1010: A term is undefined and has no properties.
If I try adding a . after container1.
for(var p: int =0; p<FavoritterID.length; p++){
trace(FavoritterID);
trace(FavoritterID.length);
trace(p);
//this['favorite'+p].nextFrame();
this.container1.(['favorite'+FavoritterID
]).nextFrame();
}
5,6,1
3
0
I get this error: TypeError: Error #1123: Filter operator not supported on type flash.display.MovieClip.
Copy link to clipboard
Copied
oliversen wrote
If I try adding a . after container1.
Stop. Stop trying to fix problems by randomly shotgunning punctuation into your code. You are only going to make this work if you actually understand what you're doing.
Copy link to clipboard
Copied
I thought I might had to use punctation when refering to a movieclip inside a container. As is common when I for instance create a eventlistener
container1.favorite22.addEventListener(...
Copy link to clipboard
Copied
oops, you don't have any objects with reference favorite0, favorite1 etc. those are all name properties. ie, use
for(var p: int =0; p<FavoritterID.length; p++){
MovieClip(container1.getChildByName('favorite'+p)).nextFrame();
}
Copy link to clipboard
Copied
Nice, I had just managed to use getChildByName to make it work for one of my buttons.
Thank you guys once again!
This is how it ended up being:
for(var p: int =0; p<FavoritterID.length; p++){
MovieClip(container1.getChildByName('favorite'+FavoritterID
)).nextFrame();
}
Copy link to clipboard
Copied
I have found a way using getChildByName
Copy link to clipboard
Copied
one of your p variables is out of range. use the trace statement to debug:
for(var p: int =0; p<FavoritterID.length; p++){
trace(p);
this['favorite'+p].nextFrame();
}
Copy link to clipboard
Copied
It stops at p=0
the error occurs right after, at the this['favorite'+p].nextFrame();
trace(p) shows 0
Find more inspiration, events, and resources on the new Adobe Community
Explore Now