Skip to main content
Participant
January 6, 2011
Question

Noob AS3 Button question.

  • January 6, 2011
  • 1 reply
  • 464 views

Hey, I have two buttons and here is my code:

import flash.events.MouseEvent;

stop();


B1.addEventListener(MouseEvent.CLICK, onB1Click);

B2.addEventListener(MouseEvent.CLICK, onB2Click);

//this will give you the hand cursor on rollover:



//now to handle the incoming click events

function onB1Click(e:MouseEvent):void

    if (this.currentFrame < this.totalFrames)

    {

        this.gotoAndStop(this.currentFrame + 1);

        trace('B1 Clicked: moved to next frame (' + this.currentFrame + ')\n');

    }

    else

    {

        trace('B1 Clicked: you are on the last frame already.\n');

    }

}



function onB2Click(e:MouseEvent):void

{  

    if (this.currentFrame > 1)

    {

        this.gotoAndStop(this.currentFrame - 1);

        trace('B2 Clicked: moved to previous frame (' + this.currentFrame + ')\n');

    }

    else

    {

        trace('B2 Clicked: you are on the first frame already.\n');

    }

}

Can Somebody tell me why this isn't working?

If anyones interested, here is a link to my flash file:
http://uploading.com/files/968cee24/Photo%2Bgallery%2B2.fla/

Thanks.

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
January 6, 2011

There is nothing wrong with the code, so it is probably something you did not set up properly.  Did you assign the instance names to the buttons in the Properties panel where it says <Instance Name>?  Are you getting any error messages?

J-MakAuthor
Participant
January 6, 2011

Hey, Thanks for the reply!

Yes, my instant names are B1 and B2.

Ned Murphy
Legend
January 7, 2011

Then you'll have to explain your design/layout... where the code is versus where the buttons are... do you animate the buttons, etc...  As I said, the code works just fine, so the issue will involve whatever way you configured things in the file.