• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint
Share this Page URL
Help

Chapter 14. Adding Behaviors > Creating and Modifying Behaviors

Creating and Modifying Behaviors

Although the behaviors in the Library palette were created by professional programmers using advanced Lingo, it’s possible to create simple behaviors of your own using the tools available in the Behavior Inspector. This section shows you how to create a new behavior and how to modify it later.

To create a behavior:

1.
Open the Behavior Inspector.

2.
Choose New Behavior from the Behavior pop-up menu (Figure 14.20).

Figure 14.20. Choose New Behavior from the Behavior pop-up menu.


The Name Behavior dialog box opens.

3.
Type a name for the behavior and click OK (Figure 14.21).

Figure 14.21. In this example, we’ll create a behavior that beeps and sends the playhead back to frame 1 when the user clicks a sprite. Let’s call it Rewind.


The dialog box closes. The newly named (but still empty) behavior is added to the Cast window (Figure 14.22), and its name is displayed in the upper pane of the Behavior Inspector.

Figure 14.22. The new behavior appears in the Cast window as soon as it’s named.


4.
If necessary, click the expander arrow to display the Behavior Inspector’s editing pane.

5.
From the Event pop-up menu, choose an event that will trigger your behavior (Figure 14.23).

Figure 14.23. Choose an event that will trigger the behavior. For the Rewind behavior, we’ll choose Mouse Down.


The selected event appears in the left column of the editing pane.

6.
From the Action Popup menu, choose a category of action and then a specific action that the event will trigger (Figure 14.24).

Figure 14.24. Choose an action that the event will trigger. For the Rewind behavior, we’ll choose Navigation > Go to Frame.


7.
If a parameters dialog box appears, set parameters for the selected action and click OK (Figure 14.25).

Figure 14.25. If a parameters box appears for the selected action, choose your settings and click OK.


The selected action appears in the right column of the editing pane.

8.
Repeat steps 5 through 7 as many times as necessary to add as many events and actions as you want (Figure 14.26).

Figure 14.26. An event may trigger multiple actions. In this case, the Sound > Beep action is added.


A behavior can have multiple events, and each event can trigger multiple actions. Actions for any event are executed in the order listed in the Actions list.

When events and actions are selected, they automatically become part of the behavior. You don’t have to do anything special to make them “stick.”

9.
Assign the behavior by dragging it from the Cast window to a sprite or frame (Figure 14.27).

Figure 14.27. The Rewind behavior is dragged to a sprite (a rewind button) on the Stage.



PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint