-
[RESOLVED] [CS3] gotoAndStop issue - probably very easy!
I have a simple 3 frame file. I've got buttons on frame 1 and 2.
The button on frame 1 should move to frame 2 and stop.
I tried this code in frame 1 (the only code so far):
Code:
stop();
btnHelp.addEventListener(MouseEvent.CLICK, gotoAndStop(2));
When I test the movie it just loops through all the frames repeatedly. If I comment out the second line it stays on frame 1.
Can anyone explain what I've done wrong?
-
Total Universe Mod
the second param in addEventListener is supposed to be the name of a function to call. adding parenthesis adds it to the call stack right away.
You need to wrap it in a function object or create separate function and pass its name.
method 1:
PHP Code:
stop(); btnHelp.addEventListener(MouseEvent.CLICK, function(){gotoAndStop(2);});
or
method 2:
PHP Code:
stop(); btnHelp.addEventListener(MouseEvent.CLICK, helpBtnHandler); function helpBtnHandler(){ gotoAndStop(2); }
-
Thanks.
I tried method 2. Now it throws an error:
ArgumentError: Error #1063: Argument count mismatch on Pong_fla::MainTimeline/btnHelpHandler(). Expected 0, got 1.
I'll copy and paste my code here, in case I made a typo:
PHP Code:
stop();
btnHelp.addEventListener(MouseEvent.CLICK, btnHelpHandler);
function btnHelpHandler() { gotoAndStop(2); }
-
The listener function needs a function argument that stands for the event. So it should actually be:
PHP Code:
function btnHelpHandler(e:MouseEvent) { gotoAndStop(2); }
And if you want to refer to the button that generated the event:
PHP Code:
function btnHelpHandler(e:MouseEvent) { e.currentTarget.alpha = .5; //this would change the button's alpha }
-
Great, it's working now.
Thanks for your help!
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|