Actionscript

420 views
350 views

Published on

action script ppt

Published in: Education
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
420
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Actionscript

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

×