Skip to main content
November 20, 2009
Answered

How to make objects appear and then disappear with buttons...

  • November 20, 2009
  • 1 reply
  • 9261 views

Hi everyone,

Im currently try to construct a flash presentation that will have several different buttons on the same stage, and each button when clicked will make particular objects appear on the stage. Then once each button is clicked again it will make the particular objects connected to it disappear from the stage. Each button and the objects it makes appear / disappear is seperate from all the other buttons actions.

I would greatly appreciate anyone who could help me construct the actionscript for this presentation as im finding it quite complicated to have several things going off on the same stage at the same time. Im currently working in Flash CS4 actionscript3.

The closest example i have seen to the program i would like to create can be found using the following link...http://steffne.deviantart.com/art/Create-your-own-fastfood-meal-138790878

However my program would be simpler, e.g. clicking the bun in the program just simply adds the bun to the screen, it doesnt scroll through different types of bun.

Thank you for you help with this

Ben

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

An easy way to toggle the visibility of objects is to make the "visible" property equal to what it is currently not.  This is done using the "!" operator ... (exclamation point)

Here's an example of a button named btn coded to make a movieclip named mc change its current visible status:

function show_hide_MC(evt:MouseEvent):void {

     mc.visible = !mc.visible;

}

btn.addEventListener(MouseEvent.CLICK, show_hide_MC);

1 reply

Ned Murphy
Ned MurphyCorrect answer
Brainiac
November 20, 2009

An easy way to toggle the visibility of objects is to make the "visible" property equal to what it is currently not.  This is done using the "!" operator ... (exclamation point)

Here's an example of a button named btn coded to make a movieclip named mc change its current visible status:

function show_hide_MC(evt:MouseEvent):void {

     mc.visible = !mc.visible;

}

btn.addEventListener(MouseEvent.CLICK, show_hide_MC);

January 10, 2014

Is there anyway you can increment and decrement a counter using this technique as it does not seem to work when I do it this way-

function show_hide_MC(evt:MouseEvent):void {

     mc.visible = !mc.visible;

     (Counter = 0) = (Counter = 1);

}

btn.addEventListener(MouseEvent.CLICK, show_hide_MC);