A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: [RESOLVED] [CS3] gotoAndStop issue - probably very easy!

  1. #1
    Junior Member
    Join Date
    Aug 2008
    Posts
    18

    resolved [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?

  2. #2
    Total Universe Mod jAQUAN's Avatar
    Join Date
    Jul 2000
    Location
    Honolulu
    Posts
    2,429
    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.CLICKhelpBtnHandler);
    function 
    helpBtnHandler(){
      
    gotoAndStop(2);


  3. #3
    Junior Member
    Join Date
    Aug 2008
    Posts
    18
    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.CLICKbtnHelpHandler);

    function 
    btnHelpHandler() {
        
    gotoAndStop(2);


  4. #4
    Junior Member
    Join Date
    Aug 2001
    Posts
    6
    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


  5. #5
    Junior Member
    Join Date
    Aug 2008
    Posts
    18
    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
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center