Skip to main content
June 1, 2013
Answered

Actionscript 3.0 when button is pressed twice turns on/off

  • June 1, 2013
  • 1 reply
  • 401 views

Alright I am new at actionscript but what I wanna do is when my button it is pressed once it brings up my input text("hiddentext") and when its pressed again it will remove it.

here is what I got.

button1_btn.addEventListener(MouseEvent.CLICK, shoot_1);

function shoot_1(event:MouseEvent):void

{

          gotoAndStop("hiddentext");{

and shoot_1 is just the identifier to make them work together.

Message was edited by: dogmer punchy

This topic has been closed for replies.
Correct answer Ned Murphy

A nice clean way of dealing with this is to put the text inside a movieclip and control the visibility of the movieclip with the button, toggling it to be the opposite of what it currently is.  If you were to assign an instance name to that movieclip like "hiddenText", the code for toggling it could be...

button1_btn.addEventListener(MouseEvent.CLICK, shoot_1);

function shoot_1(event:MouseEvent):void

{

          hiddenText,visible = !hiddenText.visible;

}

The use of the " ! " tells it to be what it is not.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 1, 2013

A nice clean way of dealing with this is to put the text inside a movieclip and control the visibility of the movieclip with the button, toggling it to be the opposite of what it currently is.  If you were to assign an instance name to that movieclip like "hiddenText", the code for toggling it could be...

button1_btn.addEventListener(MouseEvent.CLICK, shoot_1);

function shoot_1(event:MouseEvent):void

{

          hiddenText,visible = !hiddenText.visible;

}

The use of the " ! " tells it to be what it is not.