Behaviors and the Behaviors Panel


Behaviors are small pieces of code that can be placed in frames or within objects themselves. When a behavior is selected, an interface will pop up for certain parameters of the behavior to be chosen or filled in. When placing actions within objects, behaviors have events associated with them that can be adjusted directly from the Behaviors panel. Flash comes with a certain number of built-in behaviors, and you can download more from select vendors or from Macromedia. You can also create your own behaviors, which is covered in Chapter 27, "Extending Flash."

You can open the Behaviors panel by selecting Window> Behaviors. You can see the Behaviors panel in Figure 8.15.

Figure 8.15. The Behaviors panel.


Follow these steps to place a behavior in a button:

1.

Create a new Flash document.

2.

Choose Window> Common Libraries>Buttons, and choose your favorite button to drag out onto the stage.

3.

Give this button the instance name of button_btn.

4.

Open the Behaviors panel by selecting Window>Behaviors.

5.

With the button selected, click the Add Behavior button in the Behaviors panel and choose Web, Go to Web Page. The Go to URL dialog box will pop up as shown in Figure 8.16.

Figure 8.16. The interface for the Go to Web Page behavior.


6.

Type http://www.samspublishing.com in the URL field, choose "_blank" as the Open In choice, and click OK.

7.

Now the Behaviors panel will show the behavior you just placed in the button, and under the Event column, it will say On Release, which is fine.

8.

Now open up the Actions panel and select the button on the stage. You should see the following code:

 on (release) {      //Goto Webpage Behavior      getURL("http://www.samspublishing.com","_blank");      //End Behavior } 

Now test the movie by going to Control, Test Movie and then clicking the button. It should take you to something like Figure 8.17 if you are connected to the Internet.

Figure 8.17. Use behaviors to quickly add ActionScript to your files.


That was an easy and fast way to add some interactivity to the Flash file. Now we will begin to delve into the fundamental aspects of ActionScript itself including some of the built-in objects and good practices.




Macromedia Flash Professional 8 Unleashed
Macromedia Flash Professional 8 Unleashed
ISBN: 0672327619
EAN: 2147483647
Year: 2005
Pages: 319

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net