Skip to main content
TheOriginalGC
Community Expert
Community Expert
July 19, 2022
Answered

Not going to new frame in JS function

  • July 19, 2022
  • 1 reply
  • 597 views

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

This topic has been closed for replies.
Correct answer TheOriginalGC

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


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

1 reply

kglad
Community Expert
Community Expert
July 19, 2022

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.

TheOriginalGC
Community Expert
Community Expert
July 19, 2022

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?

kglad
Community Expert
Community Expert
July 19, 2022

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