11.14. Changing Movie Clip Visibility

Problem

You want to make a movie clip invisible or visible.

Solution

Set the _visible property.

Problem

Movie clip instances default to being visible. However, you can also programmatically toggle the visibility of a movie clip using the _visible property. You may be wondering why you would want to set the _visible property to false rather than simply setting the _alpha property to 0. There is a very important distinction to make between these two properties. When you set the _alpha property to 0, the movie clip may appear invisible, but it will still respond to mouse events, and can otherwise receive focus in the movie. In the event that you want to use a movie clip as an invisible button, this is exactly what you want. However, if you want to temporarily hide a movie clip from the user such that it does not even respond to mouse events, you should set the _visible property to false.

	mClip._visible = false;

You can also reinstate visibility by setting the _visible property to true:

	mClip._visible = true;

A perfect example of how you might use the _visible property is to hide a button until some other user activity (or perhaps a server response) has occurred. One such scenario might be that you might want to hide the Continue button from the user until they have completed all the requested tasks for the given “page.” On the frame on which the page is created in your Flash movie, you can initialize the button to be invisible:

 btContinue._visible = false; ...

Get Flash 8 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.