Reputation: 675
I have a very strange problem with a simple test I'm trying to do in AS3.
I have two functions on my first frame:
function function1 ():void {
trace ('function1 executed');
mc.gotoAndStop (2);
function2 ();
}
function function2 ():void {
trace ('function2 executed');
var test_mc:test_lib = new test_lib ();
addChild (test_mc);
}
As you can see, function1 changes the frame on "mc" and also calls function2, which adds a child movie clip from the library in the stage.
Function1 is called from inside another simple movie clip, on the 60th frame, like so:
Object(parent).function1 ();
This child movie clip that is added, is just a black square with a trace action on it's first frame.
The trace action should work as soon as the child is added, but it's not.
However, if I remove or comment the line mc.gotoAndStop(2)
, the trace action works normally. It also works if I put the mc.gotoAndStop(2)
AFTER I call the function2.
I can't see why this is happening.
This happened on a larger project that I was working so I decided to isolate the problem on a new file, and create the example above. This is very weird.
Upvotes: 2
Views: 112
Reputation: 712
What is mc? If mc is the MovieClip that contains both of your functions, then your code obviously cannot work because after you gotoAndStop(2), you can no longer call function2() because function2() does not exist on the second frame.
Upvotes: 0
Reputation: 1582
try shifting your function2 inside mc frame 2.
main timeline:
function function1 ():void {
trace ('function1 executed');
mc.gotoAndStop (2);
}
in mc -> on frame 2
trace ('function2 executed');
var test_mc:test_lib = new test_lib ();
addChild (test_mc);
You will have to slightly amend the code inside mc
using .root
Upvotes: 1