B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript
Agenda Why learn ActionScript ? New features in ActionScript 2.0 ActionScript elements Actions Panel and Editor Planning your script-driven project Testing and debugging scripts B.Sc. Multimedia ComputingMultimedia Authoring
Why Learn ActionScript ? More control over movie clips and their properties Animate elements independently of the timeline Import and export data dynamically Dynamic control of sound and video Create objects that have physics-driven behaviors Personalize the user’s experience B.Sc. Multimedia ComputingMultimedia Authoring
ActionScript 2.0 Features Strict data typing aVariable = 5; // no type given, compiler has to work it out aVariable:Number = 5 // declare as being a number type Case sensitive myValue not the same as myvalue Class structures for custom objects B.Sc. Multimedia ComputingMultimedia Authoring
Elements Keywords Operators Assignment Class Definition Class Method Definition Class Instantiation Class Referencing B.Sc. Multimedia ComputingMultimedia Authoring
Structure and Syntax Semicolons Curly Braces Code Blocks Dot Syntax Parenthesis Script Spacing and Layout Comments B.Sc. Multimedia ComputingMultimedia Authoring
Comments // this is a comment on one line /* these are comments spanning more than one line */ /* a script to calculate the area of a circle */ var area : Number; // holds the value of the area var PI : Number = 3.142: // sets the value of PI var radius :Number = 5 ; // sets the value of PI area = PI * radius * radius // calculates the area and assigns it to the variable B.Sc. Multimedia ComputingMultimedia Authoring
Semicolons ; and Braces {} Semicolons separate statements Curly braces define code blocks B.Sc. Multimedia ComputingMultimedia Authoring
Operators Binary + - * / Logical AND && (5 1) is False Logical OR || (5 1) is True Equalty, = Assignment a = 5 B.Sc. Multimedia ComputingMultimedia Authoring
Equality == a = ‘5’ x = 5 if (a == x) is True a = 5 x = ‘6’ if (a == x) is False B.Sc. Multimedia ComputingMultimedia Authoring
Strict Equality === a = ‘5’ x = 5 Strict equality compares types === if ( a === x) is False a = 5 x = 5 if (a === x) is True B.Sc. Multimedia ComputingMultimedia Authoring
Branching - IF Statement if(condition) { statement(s); } if(name == "Erica"){ play(); } B.Sc. Multimedia ComputingMultimedia Authoring
Branching - switch var listernerObj:Obj = new Object(); { switch (String,fromCharCode(Key.getAscii())){ case “A” : // do something here Break; case “B : // do something here break: default; B.Sc. Multimedia ComputingMultimedia Authoring
Looping: while index = 4; while (index > 0){ // do something here index = index -1; // shorthand index -- } B.Sc. Multimedia ComputingMultimedia Authoring
Looping: do while index = 4; do { // do something here index = index -1; // shorthand index -- } while (index > 0); B.Sc. Multimedia ComputingMultimedia Authoring
Class Definition class Person { var name:String; var age :Number; } B.Sc. Multimedia ComputingMultimedia Authoring
Class Constructor function Person (name:String, age:Number) { this.name = name; this.age = age; } B.Sc. Multimedia ComputingMultimedia Authoring
Method Definition function getPersonDetails () :String { return(“Name: “ + this.name + ” Age: “ + this.age); } B.Sc. Multimedia ComputingMultimedia Authoring
Class Instantiation and References var newPerson: = new Person(“Jo Smith”, 23); Classes must be saved into external actionscript files e.g. myclass.as and in the same folder as the flash movie that uses the classes B.Sc. Multimedia ComputingMultimedia Authoring
ActionScript Editor Actions Toolbox Script Navigator Script Pane
References Flash MX 2004 actionscript training from the source Franklin D. Makar J. Macromedia Press 2004 B.Sc. Multimedia ComputingMultimedia Authoring