Getting a handle on ActionScript A basic primer for non-programmers
ActionScript Similar to JavaScript Reusable pieces of code Action panel automates process Somewhat accessible for non-programmers Flash MX 2004 Utilizes ActionScript 2.0 syntax
Variables Containers for data types Comparison in Flash MX 2004 Symbols are containers for different objects you create Variables are containers you create with ActionScript They store the values of the different objects you create They can change dynamically You can see the value in Flash my using the trace function Example trace (VariableName); Trace also used as a debugging tool
Objects and Classes Classes are the blueprint to define how objects behave. Example: Dog is a member of the animal class. Dog is the object, Animal is the class. All objects are members of a Class and are instances of that Class. Objects are data types such as sound, graphics, text, numeric values
Properties Each class has a pre-defined set of properties. Each object of a class can have its own values set to its properties. Example; Movie Clip properties include: _height, _width, _rotation You can define and change the properties of each object (instance) of a Class through ActionScript.
Methods The things objects can do Example; Sound class has a setVolume method When an object does something using a method we say the method is called or that the object calls the method You can add your own methods
Objects requiring construction To use certain objects within a Class you must create an instance of the Class by giving it a name (instantiating) myColor = new Color(); myDate = new Date (); mySound = new Sound();
Calling a method The next step involves calling an object’s methods or evaluating and assigning new properties. You can call a method by entering an expression using dot syntax Example: // construct the object myDate = new Date (); // call the method of the constructed object myDisplay = myDate.getdate();
Dot Syntax Statements use dot syntax to put together objects, properties, and methods Example; movieclip1._rotation = 45 OBJECT PROPERTY VALUE We use multiple dots to maintain object hierarchy
Dot Syntax Methods are called in the same way Example; mouse. gotoAndPlay (“scene1”, 20) The parenthesis after gotoAndPlay signifies a method rather than a property The statement inside the parenthesis is an argument or a parameter
More punctuation Semicolon functions as a period does in a sentence Example: stopAllSounds(); play(); Curly braces group together related blocks of ActionScript statements on (release) { stopAllSounds(); play(); }
Actions Panel Type as in a text-editing application When you use ActionScript 2.0 syntax you get Strict Typing
Flash MX 2004 ActionScript Categories
ActionScript 2.0 More like other programming languages Strict Typing Optional Good for troubleshooting code Opens up code hinting window Example: var myVar:Number Tells Flash content of variable is a particular data type Using var is not required but tells Flash you are declaring a variable
Functions
Characteristics of Functions Functions hold other actions Allows you to control when functions are executed when you call the function
Advantages of Functions Flexible Convenient Reusable Centralized Created in one place but executed from anywhere in the movie. Ex.- three buttons in three MCs with the same purpose. We can put one copy in a function on the main timeline and invoke it from each button as needed.
Functions Fundamentals Declaration- creating them Invocation- calling the function Arguments and parameters- providing the data to manipulate Termination- ending the execution Scope- determining the availability and lifespan
Creating the function We need a function name and a block of statement to perform function functionName () { Statement one; Statement two; Statement three; } Creating the function does NOT execute the function
Running or invoking the function Simply proclaim the function’s name (invocation) on (release) { functionName (); }
Function Availability Directly accessible for invocation from: Code or button attached to timeline of movie clip that bears the function declaration Indirectly accessible using dot syntax Ex.- myClip.myOtherClip.myfunction();
Passing information to functions Statements function moveBall(){ ball._x +=10; ball._y +=10; }
Creating functions with parameters Parameters are the variables that can be used within the function We provide a list of identifiers between the parenthesis of the function declaration function moveClip (theClip, xDist, yDist) { theClip._x += xDist; theClip._y +=yDist; } We replace hard-coded values = more flexibility Allows you to modify how all the actions within that function behave
Invoking functions with parameters To pass multiple parameters we separate them with commas Each of the parameters is assigned as the value of the corresponding parameter named in the function declaration Example: on (release){ moveClip (clip1, 100, 200) }
Terminating a function Done with a return statement ActionScript does it by default at the end of a function invocation if no return statement is there Otherwise you can use return to prematurely end a function (usually done in the context of an if then statement)
Returning values from functions Return terminates a function but it can also send a value back to the script that invoked the function return expression
Function Lifespan A function defined on a movie clip timeline is lost when that clip is removed from the stage. Defining a function on the MTL is the best way to insure the function’s permanence

Actionscript

  • 1.
    Getting a handleon ActionScript A basic primer for non-programmers
  • 2.
    ActionScript Similar toJavaScript Reusable pieces of code Action panel automates process Somewhat accessible for non-programmers Flash MX 2004 Utilizes ActionScript 2.0 syntax
  • 3.
    Variables Containers fordata types Comparison in Flash MX 2004 Symbols are containers for different objects you create Variables are containers you create with ActionScript They store the values of the different objects you create They can change dynamically You can see the value in Flash my using the trace function Example trace (VariableName); Trace also used as a debugging tool
  • 4.
    Objects and ClassesClasses are the blueprint to define how objects behave. Example: Dog is a member of the animal class. Dog is the object, Animal is the class. All objects are members of a Class and are instances of that Class. Objects are data types such as sound, graphics, text, numeric values
  • 5.
    Properties Each classhas a pre-defined set of properties. Each object of a class can have its own values set to its properties. Example; Movie Clip properties include: _height, _width, _rotation You can define and change the properties of each object (instance) of a Class through ActionScript.
  • 6.
    Methods The thingsobjects can do Example; Sound class has a setVolume method When an object does something using a method we say the method is called or that the object calls the method You can add your own methods
  • 7.
    Objects requiring constructionTo use certain objects within a Class you must create an instance of the Class by giving it a name (instantiating) myColor = new Color(); myDate = new Date (); mySound = new Sound();
  • 8.
    Calling a methodThe next step involves calling an object’s methods or evaluating and assigning new properties. You can call a method by entering an expression using dot syntax Example: // construct the object myDate = new Date (); // call the method of the constructed object myDisplay = myDate.getdate();
  • 9.
    Dot Syntax Statementsuse dot syntax to put together objects, properties, and methods Example; movieclip1._rotation = 45 OBJECT PROPERTY VALUE We use multiple dots to maintain object hierarchy
  • 10.
    Dot Syntax Methodsare called in the same way Example; mouse. gotoAndPlay (“scene1”, 20) The parenthesis after gotoAndPlay signifies a method rather than a property The statement inside the parenthesis is an argument or a parameter
  • 11.
    More punctuation Semicolonfunctions as a period does in a sentence Example: stopAllSounds(); play(); Curly braces group together related blocks of ActionScript statements on (release) { stopAllSounds(); play(); }
  • 12.
    Actions Panel Typeas in a text-editing application When you use ActionScript 2.0 syntax you get Strict Typing
  • 13.
    Flash MX 2004 ActionScript Categories
  • 14.
    ActionScript 2.0 Morelike other programming languages Strict Typing Optional Good for troubleshooting code Opens up code hinting window Example: var myVar:Number Tells Flash content of variable is a particular data type Using var is not required but tells Flash you are declaring a variable
  • 15.
  • 16.
    Characteristics of FunctionsFunctions hold other actions Allows you to control when functions are executed when you call the function
  • 17.
    Advantages of FunctionsFlexible Convenient Reusable Centralized Created in one place but executed from anywhere in the movie. Ex.- three buttons in three MCs with the same purpose. We can put one copy in a function on the main timeline and invoke it from each button as needed.
  • 18.
    Functions Fundamentals Declaration-creating them Invocation- calling the function Arguments and parameters- providing the data to manipulate Termination- ending the execution Scope- determining the availability and lifespan
  • 19.
    Creating the functionWe need a function name and a block of statement to perform function functionName () { Statement one; Statement two; Statement three; } Creating the function does NOT execute the function
  • 20.
    Running or invokingthe function Simply proclaim the function’s name (invocation) on (release) { functionName (); }
  • 21.
    Function Availability Directlyaccessible for invocation from: Code or button attached to timeline of movie clip that bears the function declaration Indirectly accessible using dot syntax Ex.- myClip.myOtherClip.myfunction();
  • 22.
    Passing information tofunctions Statements function moveBall(){ ball._x +=10; ball._y +=10; }
  • 23.
    Creating functions withparameters Parameters are the variables that can be used within the function We provide a list of identifiers between the parenthesis of the function declaration function moveClip (theClip, xDist, yDist) { theClip._x += xDist; theClip._y +=yDist; } We replace hard-coded values = more flexibility Allows you to modify how all the actions within that function behave
  • 24.
    Invoking functions withparameters To pass multiple parameters we separate them with commas Each of the parameters is assigned as the value of the corresponding parameter named in the function declaration Example: on (release){ moveClip (clip1, 100, 200) }
  • 25.
    Terminating a functionDone with a return statement ActionScript does it by default at the end of a function invocation if no return statement is there Otherwise you can use return to prematurely end a function (usually done in the context of an if then statement)
  • 26.
    Returning values fromfunctions Return terminates a function but it can also send a value back to the script that invoked the function return expression
  • 27.
    Function Lifespan Afunction defined on a movie clip timeline is lost when that clip is removed from the stage. Defining a function on the MTL is the best way to insure the function’s permanence