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

Lesson 9. Built-In Behaviors > Adding Behaviors

Adding Behaviors

In this task, you'll add a behavior to animate a sprite by selecting a behavior from the Library Palette and dragging it to the sprite or sprite channel.

Choose Window > Library Palette to open the Library Palette.

Figure .

The Library Palette appears.

Figure .

In the Library Palette, you can choose from among many categories of available behaviors. Some, such as Animation, also have subcategories. For this task, you will need to select the Interactive subcategory.

Click the Library List button on the Library Palette.

The menu of available behavior groups appears.

Choose Animation > Interactive from the menu.

Figure .

The Interactive Library appears.

Click the scroll arrow at the bottom of the Library window until the Turn Towards Mouse behavior is visible.

Figure .

Place the cursor over the Turn Towards Mouse behavior icon.

A pop-up tip window appears giving a description of the behavior. You can determine the use of any of the behaviors by placing the cursor over a behavior's icon.

Click the Turn Towards Mouse behavior icon and drag it onto one of the eyeball sprites.

You can drag the icon either to the sprite itself on the stage or to the sprite channel in the score.

When you release the mouse after dragging the behavior icon onto the sprite, the Parameters dialog box appears. Most behaviors let you specify custom settings for the behavior, which allows you to tailor behaviors for individual sprites.

Figure .

Select Towards the Mouse, Always, and Remain in the New Position. Click OK.

This behavior will make the eyeball sprite rotate and "look" at the cursor when the cursor is moved on the screen. The Remain in the New Position setting for Otherwise isn't actually used, because Turn is set to Always.

This new sprite behavior is placed as a new cast member, cast member 3, in the Cast window, as shown here. The name of the cast is shown (if you have names turned on for the cast) as Turn Towards (short for Turn Towards Mouse). Notice the icon in the lower-right corner of the cast member, which indicates that the cast member is a behavior.

Figure .

On the control panel, make sure Looping is turned off. Click the Play button to play the movie and then move the cursor around the screen.

The eyeball with the behavior follows the cursor, but only for a second or so. Then the movie stops because the sprites last for only 28 frames, and you are not animating by tweening or anything else. The other eyeball does not follow the cursor on the screen, even though it is a sprite made from the same cast member as the eyeball with the behavior attached. This is because the Turn Towards Mouse behavior is attached to the eyeball sprite rather than to the eyeball cast member.

Save your work.

By just looking at the score, without sprite 2 selected, you can't tell that sprite 2 has a behavior attached to it. If you want to display the behaviors attached to the sprites in the score, you can do so by using the Display pop-up menu in the score.

In the Display pop-up menu, select Behavior.

In the score, the sprite with the attached behavior now indicates that a behavior is attached. Because no other sprites have behaviors attached, no other behaviors are shown.

Figure .

You can easily switch among different displays to show information appropriate to whatever task you are performing by choosing from the Display pop-up menu.



Not a subscriber?

Start A Free Trial

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