Presentation is loading. Please wait.

Presentation is loading. Please wait.

Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 1 by Michael Kay The Web Wizard’s Guide to Flash.

Similar presentations


Presentation on theme: "Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 1 by Michael Kay The Web Wizard’s Guide to Flash."— Presentation transcript:

1 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 1 by Michael Kay The Web Wizard’s Guide to Flash

2 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 2 CHAPTER 7 Easing into ActionScript

3 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 3 Chapter Objectives Write basic actions by hand How to apply built-in functions Understanding object-oriented programming and dot syntax Apply conditionals, operators, and variables Create a custom function Writing better ActionScript and fixing bugs

4 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 4 From Basic Actions to ActionScript The actions in Chapter 4 were all a form of ActionScript Similar to JavaScript, ActionScript is a programming language just for Flash Change the Actions to “Expert Mode” when working directly in ActionScript; and type directly in the text pane A Stop action in ActionScript: stop();

5 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 5 Anatomy of an ActionScript on(release) { tellTarget("Apple/Seed") { play(); } } tellTarget() and its open brace nest the play() action event handler and open brace nest the tellTarget() action Closing brace of tellTarget()

6 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 6 Applying setProperty() Function Requires 3 parameters separated by commas The first parameter is the path to the target object The second identifies the property to be changed The third is the value to be set for the property Use setProperty() multiple times to change more than one property setProperty("Tree/Apple",_alpha,20);

7 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 7 The trace() Function Has no effect on the appearance or behavior of published movie Used for debugging purposes, to find errors On test, displays in Output window literal text surrounded by quote marks or interprets parameter Check “Omit Trace actions” when publishing movie to improve performance trace("Output this message");

8 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 8 The getProperty() Function Like setProperty() except it finds out the current value of a property for any object Use it with the _x and _y properties to find the position of a dynamic object on the Stage Use it with the _framesloaded property to build a more accurate loading message. getProperty("_root",_framesloaded);

9 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 9 The duplicateMovieClip() function Creates a new instance of an existing movie clip Each clip is assigned its own unique level or it will replace what exists on the assigned level Combine with setProperty() to change the position and create an arrangement of instances duplicateMovieClip("Tree","Tree2",2);

10 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 10 Dot Syntax Generally, uses dots in place of slashes to define relative paths Dot syntax is a programming standard Allows you to apply a method or access a property directly by appending it to a path: Apple.Seed.play(); Use it in place of the setProperty() function: Tree.Apple._x = 200; Not compatible with Flash players earlier than version 5

11 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 11 Conditionals Use the “If” statement to set a requirement for a function If the condition is met the function will execute; otherwise it will be ignored The “else” statement allows you to define a function to be executed if a condition is not met If (condition) { someFunction() }

12 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 12 Loading Loop Conditional if (_framesloaded >= 50) { gotoAndPlay("resume_movie"); } else { gotoAndPlay("start_loop"); }

13 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 13 Variables and Operators Assign a variable as a place to store numbers, text-strings, and other values: var first_name = "Francis"; A variable name placed in an ActionScript statement will be interpreted to its stored value: trace (first_name); will display "Francis" in the output window Combine a variable with operators to change its value: xyPosition += 5;

14 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 14 Combining Variables, Operators, and Properties on (release) { if (red_circle._x < 300) { xyPosition += 20; } else { xyPosition = 0; } red_circle._x = xyPosition; red_circle._y = xyPosition; trace ("The position of the circle is " + red_circle._x + "," + red_circle._y); } Checks if the position of red_circle is less than 300 pixels from the left edge from the Stage If condition is met, xyPosition is increased by 20 Each button click will trigger script If condition is not met, xyPosition is set to 0 Moves red_circle to the new x and y positions Outputs the actual position of red_circle

15 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 15 Building a Custom Function Like a variable, define a custom function as a storage device but for other ActionScript functions and methods First, declare a function; then, call it from somewhere else to execute it. When declaring the function, define parameters with variables

16 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 16 Custom Function Example Declare Function function moveCircle (xPosition,yPosition) { red_circle._x = xPosition; red_circle._y = yPosition; } Call Function (assigned to a button) on (release) { moveCircle (150,200); }

17 Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 17 Writing Good Code Designate a separate layer for actions Start simple and build complexity gradually Use white space to improve legibility Comment code to explain how it works Check your syntax for errors Get a friend to review your code Check your work with Control > Test Movie Use the trace() function to check values


Download ppt "Copyright © 2003 Pearson Education, Inc. Chapter 7 – Slide 1 by Michael Kay The Web Wizard’s Guide to Flash."

Similar presentations


Ads by Google