Books
in black and white
Main menu
Share a book About us Home
Books
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics
Ads

Flash MX action script bible - Reinhardt R.

Reinhardt R. Flash MX action script bible - Wiley & sons , 2004. - 987 p.
ISBN: 0-7645-4354-7
Download (direct link): macractionscriptbiblefeb2004.pdf
Previous << 1 .. 46 47 48 49 50 51 < 52 > 53 54 55 56 57 58 .. 427 >> Next

▼ Properties

r • MovieClip v Instance of: Circle

[5wap... ]

W: 78.0 X: 93.0 8 H: 78.0 Y; 55.0
All we're trying to do at this point is introduce the basics of where and how to add ActionScript to a Flash movie. If you want more detailed information and examples, you'll find it as you continue reading this chapter and the next.
Chapter 4 ♦ Learning ActionScript Basics
71
objectName.eventHandlerMethodName = function ():Void {
Actions to occur on event handling go here.
};
In the example in Step 6, the object name was mcCircle, the event handler method name was onRelease, and when the event was handled the code instructed Flash to display a message in the Output panel. The name of the object variable is always the instance name you have assigned to the item on the stage. For example, if you create a button named btnAnimate, and you want to assign the same event handler method to it as in the previous example, your code would look like this:
btnAnimate.onRelease = function ():Void {
trace("Alas, poor Yorick! I knew him, Horatio");
};
You should choose the event handler method name from the list of predefined method names that are available for the specific type of object. In each of the relevant chapters in this book, you can read about the available event handler methods for a type of object. In the preceding examples we used the name onRelease because that is an event handler method that is available for both Button and MovieClip instances. That event handler method is invoked when the instance is clicked on and then released.
Another key point to understand with event handler methods is that they should be defined within a keyframe. This part might seem a little confusing because earlier we stated that actions should be defined either on a keyframe or within an event handler method. And now, we’re telling you to define the event handler method on a keyframe! This might appear to be a contradiction. In fact, the definition of the event handler method should be defined on a keyframe, but the execution of the code within the event handler method is deferred until the corresponding event takes place. For example, in Step 6 in the preceding example, the trace() action does not occur when the playhead enters the keyframe. Instead, the event handler method is defined. Then, at any point after that, if the event (in the example, the event is the click and release of a MovieClip object named mcCircle) occurs, the trace() action is executed.
Understanding the Actions Panel
If you owned the world’s most sophisticated and powerful computer, but all you knew how to do was check your e-mail with it, you might feel that the computer was a very limited thing. Similarly, if you are using Flash, but you do not familiarize yourself with all that is available within it, you are limiting your experience and the power that you can wield with it. For this reason, having a thorough understanding of the environment in which you write ActionScript can be extremely important.
Opening the Actions Panel
The Actions panel can be toggled open and closed either through the Flash menus or by keyboard shortcuts. To open and close the Actions panel using the Flash menus, choose Window O Developer Panels O Actions. If the menu item is checked, it means that the panel is already opened, and selecting it will close the panel. Otherwise, if unchecked, selecting the menu option will open the Actions panel. However, it is generally far easier and faster to use the F9 keyboard shortcut to toggle the Actions panel open and closed.
72 Part II ♦ Laying the ActionScript Foundation
Once the Actions panel has been opened, there are a few things to consider.
♦ The Actions panel defaults to being docked at the bottom of the Flash window, just above the Property inspector. You can undock the Actions panel if you prefer by clicking the panel by the gripper in the upper-left corner (as shown in Figure 4-4) and dragging it so that it displays as being undocked (no dark outline) and releasing it. When clicking the gripper, make sure the cursor changes to the cross-arrows as shown in Figure 4-4. Likewise, if you have undocked the panel, and you want to redock it, you can click on the panel on the gripper in the upper-left corner and drag it over an area of the window until the outline displays as docked. Then release it. Or you can also choose a layout from the Window O Panel Sets menu option. When you do this, however, be aware that the entire panel layout will adjust to the selected panel set.
Figure 4-4: Click the gripper on the Actions panel to dock and undock it.
♦ The title of the Actions panel should always read Actions - Frame (see Figure 4-5) before you add any code to it. If it says Actions - Movie Clip or Actions - Button, you should make sure that you have selected the correct frame, not an object instance on the stage. This is a common mistake that people make — beginners and experts alike. If you accidentally place code on a MovieClip or Button i nstance instead of a frame, you will get an error when you try to export the movie. The error will read something like this:
Previous << 1 .. 46 47 48 49 50 51 < 52 > 53 54 55 56 57 58 .. 427 >> Next