Join David Gassner for an in-depth discussion in this video Showing and hiding movie clip instances, part of Flash Professional CS5: Code Snippets and Templates in Depth.
- View Offline
It's very common in a Flash movie to create objects on the Stage that you want to have hidden when the movie first appears to the user. You handle this by setting a property called Visible to a value of False and you do this in ActionScript code. You can use a code snippet to create this code very simply and easily. I'll start this demonstration with a file from the Exercise Files area, in the Ch01_SimpleSnippets folder named OliveGameWithLabels.fla. In the beginning state of this movie I have six layers in the timeline.
The three layers named rosemaryLabel, orangeLabel, and jalapenoLabel, each of these contains a single label object. And in the bottles layer, there are three movie clip instances showing images of bottles. The labels are designed to be displayed one at a time. As the movie first appears in Flash Player, I don't want them to be shown. So I need to set the Visible property to False. There's a very simple way of doing that, again, using a code snippet.
I'll start in the first layer named rosemaryLabel. I'll right click and choose Lock Others and then this will allow me to choose the one and only object in the layer. After I've selected the object I can then apply a code snippet to it. I'll go the menu and choose Window > Code Snippets and then I'll go to the Actions category. There are two possible code snippets you can use here. One is named Click to Hide an Object and the other is named Show an Object. I want to hide the object but I don't want to respond to a mouse click.
So I am going to start off with the Show an Object code snippet and I'll double click it, which will add an Actions layer and add the bit of code I need. Here is the code that's been added, rosemaryLabel_mc.visible=true. Now what I really want to do is hide the object when the movie first appears, so I'll change the value of true to false. And then I'll delete the comments that are added at the top of the code snippet. I don't really need them. Now I am going to repeat the process for the other two label objects.
I'll close the Actions panel. Next I'll go to the orangeLabel layer, right-click, and select Lock Others. Then I'll click in the layer to select the one and only object in that layer and once again I'll double click on Show an Object. I'll change the value of the Visible property from true to false and, once again, I'll delete the comments. I'll move the cursor down to the bottom of the existing code and I'll repeat this one more time, this time for jalapenoLabel. I'll right on the layer, choose Lock Others, click to select the object, double click on the code snippet, change the value from true to false, delete the comments, and now as the movie shows up in Flash Player, these three objects should be invisible.
I'll close the Actions panel and then test the movie. Now the labels don't appear in the movie. Now in another video, I'll show you how to use those labels and show you how to make them appear and disappear as the mouse floats over each of the three bottle images. Once again, I'll use code snippets to build the code and do a little bit of customization along the way.
- Touring the Code Snippets panel
- Adding simple and complex code snippets
- Handling mouse and keyboard events
- Starting and stopping video and sounds
- Loading external SWF files, images, and text
- Customizing code snippets
- Understanding template types and categories
- Replacing template content
- Creating a slide show