10 Minutes with Flash: Writing Custom Behaviors

Don't you wish Flash MX 2004 came with more built-in behaviors? Well, the good news is that you can still create your own behaviors and save yourself lots of coding time by modifying existing behaviors to create your own. In only 10 minutes or less, Robert Hoekman, Jr. helps you create your own behaviors and save yourself lots of grief.

From the author of

From the author of

Flash MX 2004 introduced us to the world of behaviors: ActionScripts
that get written for you via the Behaviors panel. Macromedia seems to think that
the Behaviors panel is a good replacement for the now extinct Normal mode (which
had a similar function and a lot more options). Whether or not you agree, the
Behaviors panel can in fact offer a viable alternativeif you know how to
write XML and are willing to create your own behaviors.

What's that? You don't know how to write XML? Well, the good news
is that you can still create your own behaviors and save yourself lots of coding
time by modifying existing behaviors to create your own. In this installment of
the 10 Minutes with Flash series, you'll create a behavior that hides the
contextual menu in a published SWF. After you have a handle on how it's
done, you'll be better-equipped to turn that pesky Behaviors panel with its
incredibly short list of possible functions into something more useful.

The Behaviors What Now?

Like many people, you may not have noticed the Behaviors panel while looking
through the list of new features in Flash MX 2004. And I don't blame you.
It doesn't appear at first to be one of the more groovy happenings in the
world of Flash development. But alas, it is. Let's take a quick look at
what it does.

Put any ol' JPG onto your desktop and name it
test.jpg.

Launch Flash MX 2004 or Flash Pro and save a new document as
test.fla to your desktop.

Choose Window > Development Panels > Behaviors to open the
Behaviors panel, shown in Figure 1.

Cool, huh? You chose a script from a menu and Flash wrote it for
youwith commentsto identify its purpose and separate it from the
pack of code blocks that will eventually fill up your Actions panel. Granted,
this isn't the most exciting script in the world, but hey, you didn't
have to write it yourself, so you probably saved at least five seconds. If you
didn't know how to load an external graphic at all, this likely saved you a
lot of time.

Now that you're familiar with what behaviors can do for you, you can
write one of your own.