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

Not going to new frame in JS function

Community Expert ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

So I have a movieclip with 3 frames and when I call the instance from the library (as shown below) it's not switching to the desired frame. The ultimate goal is to have multiple instances with random frames chosen, but it is currently not chosing any other frame. I have tested this by adding the object to the stage and it works fine, just not when I'm calling it from the library.

 

function testInit(){
var star = new lib.star();
star.gotoAndStop(1); //this does nothing?
star.x = 346;
star.y = 386;
stageRoot.addChild(star);  // stageRoot = this
}

testInit();

TOPICS
Code , How to

Views

215

Translate

Translate

Report

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 , Jul 19, 2022 Jul 19, 2022

Perfection. I broke apart the symbol and I was able to change the fill color. Thing works perfectly now. Bizarre. 

Votes

Translate

Translate
Community Expert ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

stageRoot needs to be defined or use:

 

function testInit(){
var star = new lib.star();
star.gotoAndStop(1); //this does nothing?
star.x = 346;
star.y = 386;
this.addChild(star); // stageRoot = this
}

testInit.bind(this)();

 

p.s. frame 1 is the 2nd frame.

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Everything you say is correct. I accidently left off the variable defining stageRoot. The instance is appearing as it's supposed to. The instance is defaulting to frame 0 no matter what. Any other suggestions?

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

does frame 0 have a this.stop() on it?

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Not at the moment. Does it need it? gotoAndStop() seems to work when I place it on the stage.

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

no, it doesn't need a this.stop(), but it indicates you have something on-stage that looks like star's frame 0 and you're mistaking that for the one added by testInit().  ie, if your code where adding star (and only the goto were failing), star would be cycling through its 3 frames.

 

create a new fla

drag star from your problematic library to the new library

copy and paste your code into the new fla

test

 

any problem?

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Give me a sec, I'll let you know.

 

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Well that worked, so I'm going to try something different.

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

Perfection. I broke apart the symbol and I was able to change the fill color. Thing works perfectly now. Bizarre. 

Votes

Translate

Translate

Report

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 ,
Jul 19, 2022 Jul 19, 2022

Copy link to clipboard

Copied

LATEST

all's well that ends well.

Votes

Translate

Translate

Report

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