60
Basic Tasks: Creating a banner, Part 2
Before you add the code, you need to give the button a unique instance
name. The instance name enables you to target the button with
ActionScript code. If you don't name the button, your code doesn't have a
way of targeting the button from the timeline. The first step is to assign the
invisible button an instance name, and then you add code that targets that
button using its name.
1.
Select the invisible button on the Stage.
2.
Open the Property inspector (Window > Properties), and find the
Instance Name text box in the Property inspector.
3.
Type
inv_btn
into the Instance Name text box.
4.
Select Insert > Timeline > Layer to insert a new layer, and then rename
the new layer to
actions
.
5.
Open the Actions panel (Window > Actions), and then select Frame 1
of the actions layer.
6.
Type the following ActionScript into the script pane (the editable text
field) in the Actions panel:
inv_btn.onRelease = function(){
getURL("http://gnome.deseloper.com", "_blank");
};
Notice how you target the
inv_btn
instance in the first line of code.
The event is the
onRelease
event in your ActionScript code, which
refers to the action when a user clicks and then releases the mouse over
the
inv_btn
instance. Then you tell the button to open a particular
web page (http://gnome.deseloper.com) in a new window (
_blank
)
using the
getURL()
method. Obviously, you would replace this URL
with whatever website you want the banner to open. If you want the
banner to open the website in the current page, replace
_blank
with
_self
.
This is a simple piece of ActionScript code that reacts to a button click.
There is a lot of additional information on learning the ActionScript
language in the Flash 8 documentation. Refer to the documentation's
Table of Contents, and find
Learning ActionScript 2.0 in Flash
.
NO
TE
An instance name is different from the symbols name (which is what you
type in the Name text box in the Convert to Symbol dialog box). An
instance name cannot have spaces or special characters, but you can use
underscores. Also, your instance names are case-sensitive.
Содержание FLASH 8-FLASH
Страница 1: ...Flash Tutorials...
Страница 10: ...10 Contents...
Страница 12: ...12 Introduction...
Страница 42: ...42 Basic Tasks Creating a banner Part 1...
Страница 78: ...78 Basic Tasks Creating a banner Part 3...
Страница 88: ...88 Basic Tasks Create Accessible Flash Content...
Страница 106: ...106 Basic Tasks Create an Application...
Страница 116: ...116 Basic Tasks Use Layout Tools...
Страница 124: ...124 Basic Tasks Create Symbols and Instances...
Страница 134: ...134 Basic Tasks Add Button Animation and Navigation...
Страница 144: ...144 Basic Tasks Create a Presentation with Screens Flash Professional Only...
Страница 192: ...192 Creating Graphics Applying Gradients...
Страница 198: ...198 Creating Graphics Apply Graphic Filters and Blends Flash Professional Only...
Страница 224: ...224 ActionScript Use Script Assist mode...
Страница 268: ...268 ActionScript Work with Objects and Classes...
Страница 270: ...270 Data Integration Overview Flash Professional Only...