Mouse Event - Hide Object

Mouse Event - Hide Object

Flash CS4 ActionScript 3.0 Tutorial


How to Click on an Object to make it Disappear in Flash



There are numerous events that occur in flash. Once an event happens, a function is run. Examples of events include clicking a button, mousing over an object and checking the progress of a download.

You can also have events that are tied to the document's frame rate. In other words, if you're project is set to 24 frames per second (fps), the event occurs 24 times per second.

In this example we will illustrate how to create a MouseEvent that triggers a function. The function is also called the Event Handler. When the user's mouse clicks on a Movie Symbol, the function makes the Movie Symbol to disappear.

For more information on Events, see topics, Enter Frame Event - Rotate Object at Current Frame Rate, Keyboard Press - Move Object, Mouse Event - Drag Object and Timer Event - Count a Number.

Tutorial Elements

Movie Symbol with instance name of oval_mc


Step One

Open a new document and add a new layer above the default layer.

Step Two

Name the upper layer Actions and the lower layer Content.

Step Three

Using the Oval tool, add an oval object to the Content layer.

Step Four

Select the oval object and press F8 to convert it to a Movie Symbol.

Step Five

With oval Movie Symbol selected, assign it an instance name of oval_mc in the Properties panel.

Step Six

Open the ActionScript panel for your keyframe in the Actions layer by Option double-clicking (PC - Alt double-clicking) the keyframe

Step Seven

Copy/Paste the following code in the ActionScript Panel:

oval_mc.addEventListener(MouseEvent.CLICK, onClick01);

function onClick01(e:MouseEvent):void {



Step Eight

Click the Auto Format button to format the code

Step Nine

Test your movie by pressing Cmd/Return (PC - Ctrl/Enter). Click the oval object and it disappears.

Dissecting the Code

The first line of the code at Step Seven adds an event listener to oval_mc. Whenever the oval is clicked, the onClick01 function is triggered.

The next lines of code define the function. Each time the function is called, the oval_mc disappears.

This Causes That

Events (oval_mc click) and Event Handlers (onClick01 function) work as a team. When you click the Movie Symbol, the function is run.