![MACROMEDIA FLASH MX 2004-LEARNING FLASH Скачать руководство пользователя страница 109](http://html1.mh-extra.com/html/macromedia/flash-mx-2004-learning-flash/flash-mx-2004-learning-flash_manual_3379009109.webp)
Add conditional logic for the Submit button
109
Add frame labels for navigation
When the viewer presses the Submit button, you want Flash to jump to either the error message
or the confirmation message, depending on what is entered in the text field. Labeling a frame
helps you easily reference it in ActionScript. This is helpful for sending the playhead to a
specific frame.
Next, you’ll add frame labels to help you navigate your Flash application.
1.
Add a keyframe (Insert > Timeline > Keyframe) to Frame 5 of the Actions layer.
2.
In the Property inspector, type
error
in the Frame Label text box. Press Enter or Return.
The label text and a flag appear in Frame 5 of the Timeline.
3.
Add a keyframe to Frame 10 of the Actions layer. In the Property inspector, type
confirm
in the
Frame Label text box. Press Enter or Return.
Add conditional logic for the Submit button
With ActionScript, you can have Flash compare information and take action based on criteria you
specify. In this example, you’ll add ActionScript for Flash to take one action if the user enters no
data in the text field, and a different action if the user does.
1.
Select Frame 1 of the Actions layer. In the Script pane, place the insertion point after the
stop();
code. Press Enter or Return.
2.
Type the following comment:
//Adds conditional logic for the Submit button that
validates user input
. Press Enter or Return.
3.
In the Actions panel, click the Insert a Target Path button, located at the top of the panel.
4.
In the Insert Target Path dialog box, verify that Relative is selected. Click submit_btn on the
hierarchical tree, and click OK.
5.
In the Script pane, type a period (
.
) after
submit_btn
, and then type
onRelease
.
6.
With the insertion point after
onRelease
, type
= function (){}
in the Script pane.
7.
Place the insertion point between the curly braces and press Enter or Return, and then type
if
(url_txt.text == null || url_txt.text == ""){
in the Script pane.
The parallel lines are equivalent to logical
or
in ActionScript.
8.
With the insertion point still inside the curly braces, press Enter or Return.
9.
Type
gotoAndStop("error");
in the Script pane. Press Enter or Return.
10.
Place the insertion point after the curly brace and type
else{
in the Script pane. Press Enter or
Return.
Содержание FLASH MX 2004-LEARNING FLASH
Страница 1: ...Learning Flash...
Страница 8: ...8 Contents...
Страница 34: ...34 Chapter 3 Write Scripts with ActionScript...
Страница 54: ...54 Chapter 6 Create a User Interface with Layout Tools...
Страница 62: ...62 Chapter 7 Draw in Flash...
Страница 68: ...68 Chapter 8 Create Symbols and Instances...
Страница 76: ...76 Chapter 9 Add Animation and Navigation to Buttons...
Страница 104: ...104 Chapter 13 Add Interactivity with ActionScript...
Страница 112: ...112 Chapter 14 Create a Form with Conditional Logic and Send Data...
Страница 122: ...122 Chapter 15 Work with Objects and Classes Using ActionScript 2 0...