Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

next frame movieclips

Participant ,
Jun 18, 2018 Jun 18, 2018

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

742
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jun 18, 2018 Jun 18, 2018

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();

}

Translate
Community Expert ,
Jun 18, 2018 Jun 18, 2018

use array notation to coerce strings to objects:

user

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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 18, 2018 Jun 18, 2018

Fixing the use of "ii" as the iterator variable would also help. And the comma in the for loop instead of a semicolon.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2018 Jun 18, 2018

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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2018 Jun 18, 2018

I was thinking it might had to do with the buttons being placed inside container1. But it didnt seem to change anything.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 18, 2018 Jun 18, 2018

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();

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2018 Jun 18, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Jun 18, 2018 Jun 18, 2018

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2018 Jun 18, 2018

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(...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2018 Jun 18, 2018

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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2018 Jun 18, 2018
LATEST

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();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2018 Jun 18, 2018

I have found a way using getChildByName

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jun 18, 2018 Jun 18, 2018

one of your p variables is out of range.  use the trace statement to debug:

user

for(var p: int =0; p<FavoritterID.length; p++){

trace(p);

this['favorite'+p].nextFrame();

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Participant ,
Jun 18, 2018 Jun 18, 2018

It stops at p=0

the error occurs right after, at the this['favorite'+p].nextFrame();

trace(p) shows 0

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines