24
XP Tutorial 8 Adding Interactivity with ActionScript

XP Tutorial 8 Adding Interactivity with ActionScript

Embed Size (px)

Citation preview

XP

Tutorial 8

Adding Interactivity with ActionScript

New Perspectives on Macromedia Flash MX 2004

2

XPProgramming with ActionScript

• ActionScript is a robust programming language that gives the Flash developer an almost unlimited number of ways to make a Flash document interactive.

• ActionScript can also be used to write complete programming applications such as a shopping card application in which the user can enter data, make selections, and then make a purchase.

New Perspectives on Macromedia Flash MX 2004

3

XPProgramming with ActionScript

Input fields

Make selections here

New Perspectives on Macromedia Flash MX 2004

4

XPWorking with Objects and Properties

• ActionScript is used to control and modify objects.

• An object is an element in Flash that has properties or characteristics that can be examined or changed with ActionScript.

• Working with objects in ActionScript often requires that you assign names to them.

New Perspectives on Macromedia Flash MX 2004

5

XPWorking with Objects and Properties

New Perspectives on Macromedia Flash MX 2004

6

XPUsing Actions, Methods, and Functions

• An action is a statement that instructs a SWF file to do something.

• Functions are blocks of statements that process information and return a value or perform some action.

• The values you send to a function are called parameters or arguments and are enclosed in parentheses.

• Methods are functions specific to a particular object.

New Perspectives on Macromedia Flash MX 2004

7

XPWriting ActionScript Using Variables, Expressions, Operators, and Comments

• A variable is a container that holds information while the SWF file s playing.

• A keyword is a word or phrase that already has a specified use or meaning in ActionScript and cannot be reused in another context in a statement.

• An expression is a statement that is used to assign a value to a variable.

• String data is a series of characters, such as letters, numbers, and punctuation, and is always enclosed in quotation marks.

New Perspectives on Macromedia Flash MX 2004

8

XPWriting ActionScript Using Variables, Expressions, Operators, and Comments

• Numeric data is a number or numbers that are not enclosed in quotes.

• Operators are used in expressions to tell Flash how to manipulate the values in the expression.– The equal sign is an example of an assignment operator– ActionScript also has arithmetic operators, such as +, -, *, and /– A comparison operator is used in conditional statements– A conditional statement is one in which one value is compared to

another.

• Comments are notes within the ActionScript code that explain what is happening.

New Perspectives on Macromedia Flash MX 2004

9

XPComments

Comment in Script Pane

New Perspectives on Macromedia Flash MX 2004

10

XPWriting ActionScript Code

• When writing ActionScript code, you need to follow certain rules, known as the syntax of the language.

New Perspectives on Macromedia Flash MX 2004

11

XPLinking to Web Sites Using the getURL() Function

• The getURL() function loads a document such as a Web page into a browser window.

• The format is getURL(url, window)– url is the address of the Web site you want to open in

the browser window

– The argument window can be one of several options

New Perspectives on Macromedia Flash MX 2004

12

XPThe window Argument

• _self—Specifies that the Web site document be opened in the current browser window; this replaces the currently displayed document

• _blank—Specifies that the Web site document be opened in a new browser window; the currently displayed document remains opened in its own browser window

• _parent—Specifies that the Web site document be opened in the parent of the current frame; this applies when you are using frames to display your Web site; frames split the browser window into more than one window and allow you to display several Web documents at one time

• _top—Specifies that the Web site document be opened in the top-level frame in the current window; this applies when you are using frames to display your Web site

New Perspectives on Macromedia Flash MX 2004

13

XPgetURL() Function

getURL ( ) function

arguments

New Perspectives on Macromedia Flash MX 2004

14

XPCreating an Input Form

• An input form is a common element found on many Web sites on the Internet.

• An input form allows the user to enter data into input fields.

• A page developed with Flash can allow the user to enter data, have the data processed, and return a result directly from the Flash Player on the user’s computer.

New Perspectives on Macromedia Flash MX 2004

15

XPUsing Dynamic and Input Text

• Static text cannot be changed after the document plays in the Flash Player.

• Dynamic text can receive text in the form of characters or numbers from a Web server or from an expression in ActionScript and display the text on a Web page in the Flash Player.

New Perspectives on Macromedia Flash MX 2004

16

XPUsing Dynamic and Input Text

New Perspectives on Macromedia Flash MX 2004

17

XPDynamic Text Options

Refer to figure 8-16 in your text for a summary of Dynamic Text Options including:

Instance Name text box

Line type list box

Selectable button

Render text as HTML button

Show border around text button

Variable text box

Edit characters options button

New Perspectives on Macromedia Flash MX 2004

18

XPInput Text

• Input text is used to allow the user to enter text into the text block.

• This text can then be stored in a variable and used in an ActionScript script.

• To create an input text block, use the Text tool and select Input Text from the Text type list box in the Property inspector.

New Perspectives on Macromedia Flash MX 2004

19

XPOptions for Input Text

Text type list box

Maximum Characters Allowed text box

New Perspectives on Macromedia Flash MX 2004

20

XPUsing a Flash Preloader

• A SWF file is downloaded over the Internet from a Web server to the user’s computer, known as the client computer.

• A major factor that affects the amount of time it takes a file to download is the size of the file, measured in kilobytes.– A kilobyte is approximately 1000 bytes.

– A byte is equivalent to one character of information.

New Perspectives on Macromedia Flash MX 2004

21

XPUsing a Flash Preloader

• Flash files are streaming, which means that as the file is downloading, the initial content can start playing while to rest of the content continues to be downloaded.

• Flash developers usually add a preloader, which is a short animation or message located in the first few frames of the Flash file.

• The preloader typically contains a short animation and the word “Loading” to indicate to the site visitor that the Web site is still loading.

New Perspectives on Macromedia Flash MX 2004

22

XPSample Preloaders

New Perspectives on Macromedia Flash MX 2004

23

XPPreloader Logic

• The pseudocode for the preloader logic is as follows:– Get the total number of bytes

– Get the number of bytes loaded

– If the number of bytes loaded equals the total number of bytes

Play the rest of the SWF fileelse

continue playing the preloader animation

New Perspectives on Macromedia Flash MX 2004

24

XPPreloaders