250 likes | 738 Views
ActionScript A Primer ActionScript is… Object-oriented programming Everything you do in ActionScript does something to some object* Some objects are called Symbols in Flash Movie Clip Graphic Button * anything you can manipulate in some way Object oriented?
E N D
ActionScript A Primer
ActionScript is… • Object-oriented programming • Everything you do in ActionScript does something to some object* • Some objects are called Symbols in Flash • Movie Clip • Graphic • Button *anything you can manipulate in some way
Object oriented? • You can decide what happens when a user clicks a button without worrying about how the button (or program) knows that it has been clicked • You can decide what changes to make to an object’s properties without knowing the internal mechanics of how those changes were made • You can program tasks incrementally without sitting down and writing the whole program from start to finish in one session
ActionScript Deconstructed • Class: a group of items that are similar in some way • Items are called objects or instances of the class • Objects can be concrete (like a button or graphic) or abstract (like a variable that is invisible, but hold data) • Objects have two aspects form (properties) and function (methods) • Each property and method is defined by Actions (pieces of code that tell Flash how to manipulate a target object at any point in your movie).
ActionScript Metaphor • Ball could be considered a class of items defined as “spherical things” • One object in this class is a movie clip called Tennis_ball • The properties of Tennis_ball might be the color neon green or a 20-pixel diameter • Its methods might be bounce, roll, and/or spin • A 2ndobject in the ball class might be Softball • Properties white…etc.
ActionScript Flow • Flash executes ActionScript statements starting with the first statement and continuing in order until it reaches the final statement or a statement that instructs ActionScript to go somewhere else.
One type of action that sends ActionScript somewhere other than the next statement is an if statement
Actions • Tell Flash to do something • Frame actions • Object actions • Actions also can have parameters
gotoAndPlay • This frame action sends the playhead to the specified frame in a scene and plays from that frame. If no scene is specified, the playhead goes to the specified frame in the current scene.
Functions • Perform a specific task • Like in a spreadsheet program (Excel)
getVersion • Returns the Flash Player version number and operating system information. • You can use this function to determine whether the Flash Player that is in use can handle your Actionscript.
Properties • All available information about an object • You can use ActionScript to read and modify object properties • All property names begin with an underscore (e.g., _visible)
_visible = false • This property make an object invisible • Assign the following action to a button… On (release) { _visible = false; } • Button disappears on mouse click
Method • Similar to actions in that they effect objects • Built into objects • Invoked (Executed) through dot notation
RocketMC.gotoAndPlay(“BlastOff”); • ActionScript notation must end in ; • Movie clip Rocket MC goes to a frame labeled BlastOff and plays
Variables • hold data for use in your Flash movies • Variables can hold any type of data • You could store: • User name • Result of calculation • True or false value
Expressions • An expression is any statement that Flash can evaluate and that returns a value. • You can create an expression by combining operators and values or by calling a function.
Operators • Expressions use operators to tell Flash how to manipulate the values in the expression. • They are the commands that say “add these values” or “multiply these numbers”
Some types of operators • Assignment: • are used to assign values to variables. • The most common is (=). It makes the variable on the left equal to the value of the variable or expression on the right. • Comparison and equivalence: • (<), (>), (< =) • Numeric: • perform mathematical operations on values
Looping • When you need to repeat certain actions in your movies more than once. • Makes coding more efficient, using the same set of commands as many times as necessary to complete a task.
Looping examples • while • Creates a loop that continues to repeat as long as a condition remains true • for • Creates a loop that executes a specific number of times using a counter • for…in • Creates a loop that executes once for each member of a group of objects (class) • This makes certain that the entire group of objects is processed in the same way
Hints • Before you begin writing scripts, formulate your goal and understand what you want to achieve. • Planning your scripts is as important as developing storyboards for your work. • Start by writing out what you want to happen in the movie, as in this example: • I want to create my whole site using Flash. • Site visitors will be asked for their name, which will be reused in messages throughout the site. • The site will have a draggable navigation bar with buttons that link to each section of the site. • When a navigation button is clicked, the new section will fade in at the center of the Stage. • One scene will have a contact form with the user's name already filled in.