Presentation is loading. Please wait.

Presentation is loading. Please wait.

B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript 3.0.

Similar presentations


Presentation on theme: "B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript 3.0."— Presentation transcript:

1 B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript 3.0

2 Agenda Simple Types Variables Assignment Boolean Comparisons Control Structures Branching and Looping Introduction to Arrays B.Sc. Multimedia ComputingMultimedia Authoring

3 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

4 Structure and Syntax Semicolons ; Curly Braces {} Code Blocks Dot Syntax ( for functions “methods”) Parenthesis Style Script Spacing and Layout Comments B.Sc. Multimedia ComputingMultimedia Authoring

5 ActionScript 3.0 Typing Strict data typing aVariable = 5; // no type given, compiler error 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

6 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

7 Semicolons ; and Braces {} Semicolons separate statements statementOne; statementTwo; statementThree; Curly braces define code blocks { statementOne; stateMentTwo statementThree } B.Sc. Multimedia ComputingMultimedia Authoring

8 Operators Binary + - * / Logical AND && (5 1) is False Logical OR || (5 1) is True Equalty, = Assignment a = 5 B.Sc. Multimedia ComputingMultimedia Authoring

9 Equality == a = ‘5’ x = 5 if (a == x) is True a = 5 x = ‘6’ if (a == x) is False B.Sc. Multimedia ComputingMultimedia Authoring

10 if statements if(condition) { statement(s); } e.g. var firstNumber:int = 25; var secondNumber:int = 39; if(firstNumber==secondNumber){ trace("Snap!"); } B.Sc. Multimedia ComputingMultimedia Authoring

11 if..else B.Sc. Multimedia ComputingMultimedia Authoring var firstNumber:int = 25; var secondNumber:int = 39; if(firstNumber==secondNumber){ trace("Snap!"); } else { trace("Not a match"); }

12 switch B.Sc. Multimedia ComputingMultimedia Authoring var thisMonth:int = new Date().getMonth(); switch (thisMonth) { case 0 : trace( "January"); break; case 1 : trace("February"); break; case 2 : trace( "March"); break; default: trace(“Some other month”); } // endSwitch

13 Looping: while index = 4; while (index > 0){ // do something here index = index -1; // shorthand index -- } B.Sc. Multimedia ComputingMultimedia Authoring

14 Looping: do while int:index = 4; do { // do something here index = index -1; // shorthand index -- } while (index > 0); B.Sc. Multimedia ComputingMultimedia Authoring

15 B.Sc. Multimedia ComputingMultimedia Authoring Using Arrays in Flash

16 How to Store Five Numbers Use individual variables for each number stored: var numberOne:number var numberTwo:number var numberThree:number var numberFour:number var numberFive:number messy - have to process as individual items rather than as a collection of grouped items. Solution - use an Array - contiguous data storage B.Sc. Multimedia ComputingMultimedia Authoring

17 Arrays and Data Storage B.Sc. Multimedia ComputingMultimedia Authoring 15 95 14 70 23 Elements Size of the array is 5 The value stored at array element number 2 is 14 Array element numbering starts at 0 0 3 2 4 1

18 Arrays and Data Storage B.Sc. Multimedia ComputingMultimedia Authoring 15 23 14 70 5 Array of numbers (integers) Gibson Fender Punk Martin Array of strings Les Paul

19 Declaring Arrays in Flash B.Sc. Multimedia ComputingMultimedia Authoring // create a new array var numberArray:Array = new Array(); // store the numbers into the array // 15 95 14 70 23 numberArray[0] = 15; numberArray[1] = 95; numberArray[2] = 14; numberArray[3] = 70; numberArray[4] = 23;

20 Looping through an Array B.Sc. Multimedia ComputingMultimedia Authoring // total the numbers stored in the number array var index:Number; var sum:Number; sum = 0; for (index = 0; index <= 4; index = index + 1){ sum = sum + numberArray[index] } trace("The sum of the numbers in the array is " + sum)

21 Looping through an Array 2 B.Sc. Multimedia ComputingMultimedia Authoring // total the numbers stored in the number array using array length method var index:Number; var sum:Number; sum = 0; for (index = 0; index < numberArray.length; index++){ sum = sum + numberArray[index] } trace("The sum of the numbers in the array is " + sum)

22 References ActionScript 3.0 Language Reference Adobe Livedocs B.Sc. Multimedia ComputingMultimedia Authoring


Download ppt "B.Sc. Multimedia ComputingMultimedia Authoring Introduction to ActionScript 3.0."

Similar presentations


Ads by Google