Recipe 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; 

Then, after all the tasks have been completed, you can make the button visible:

 btContinue._visible = true;  

The _visible property is a very important property as you begin to move from basic Flash movie architecture to more advanced architectures. You can actually create multiple "pages" all within a single keyframe, and by using the _visible property you can switch between them. This has many advantages, including:

  • It is easier to maintain user state. For example, if you have a form as one of your pages, you can allow the user to switch back and forth between the form and other sections without losing the information the user has filled out already.

  • You can generate your entire movie using ActionScript. Although when you use Flash as a standard animation tool, it does not always make sense to try to generate your entire movie using code, in many other cases it can be quite advantageous, because you can have more programmatic control over things.

You can see many more examples of how to use _visible to perform these kinds of advanced ActionScript tasks in the ActionScript Cookbook (O'Reilly).




Flash 8 Cookbook
Flash 8 Cookbook (Cookbooks (OReilly))
ISBN: 0596102402
EAN: 2147483647
Year: 2007
Pages: 336
Authors: Joey Lott

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net