Skip to main content
Known Participant
February 23, 2010
Question

2 CLICK functions on 1 button

  • February 23, 2010
  • 3 replies
  • 434 views

Hello,

I'm making a menu in flash and I want that when I CLICK the button/movieclip moves up and when I CLICK again it moves down again.

I allready did it with MOUSE_OVER and MOUSE_OUT but that gave me problems.

Somebody any Idea's?

Here is the Code:

//Eventlisteners

menu_over.buttonMode = true;
menu_over.addEventListener(MouseEvent.MOUSE_OVER,onOver,false,0,true);
menu_over.addEventListener(MouseEvent.CLICK,onOut,false,0,true);

//Functions

function onOver(e:MouseEvent):void {
menu_over.gotoAndPlay("menu_op");
}
function onOut(e:MouseEvent):void {
menu_over.gotoAndPlay("menu_beneden");
}

Thanks

This topic has been closed for replies.

3 replies

February 23, 2010

You could use a flag variable:

var:isOpen:Boolean = false;

//Eventlisteners

menu_over.buttonMode = true;
menu_over.addEventListener(MouseEvent.CLICK,onOut,false,0,true);

//Functions

function onOut(e:MouseEvent):void {

  if(!isOpen){

    menu_over.gotoAndPlay("menu_op");

    }else{
    menu_over.gotoAndPlay("menu_beneden");

  }

isOpen = !isOpen;
}

Ned Murphy
Legend
February 23, 2010

Create another variable for your movieclip as a boolean type... maybe naming it something like "isDown" if down is the initial condition.  Then in your click function have a conditional that takes an action depending on whether isDown is true or false and toggle the value to the opposite state after that.

var isDown:Boolean = true;

function onClick(evt:MouseEvent):void {

     if(isDown){

          // move up

     } else {

          // move down

     }

     isDown = !isDown;

}

Inspiring
February 23, 2010

Hi,

This may help you

menu_over.addEventListener(MouseEvent.CLICK,onOut,false,0,true);

//Functions
var myBoolean:Boolean = false;

function onOut(e:MouseEvent):void {

    myBoolean = !myBoolean
    if(myBoolean)
    {
        menu_over.gotoAndPlay("menu_op");
    }
    else
    {
        menu_over.gotoAndPlay("menu_beneden");
    }

}