0% found this document useful (0 votes)
48 views

Getting A Handle On Actionscript: A Basic Primer For Non-Programmers

ActionScript is a scripting language similar to JavaScript that is used to add interactivity to Flash projects. It allows for reusable pieces of code called functions. Functions help organize code and make it more flexible by allowing sections of code to be executed from multiple places. Functions can accept parameters to make them more dynamic and return values. Understanding functions is an important part of learning ActionScript.

Uploaded by

user1230
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Getting A Handle On Actionscript: A Basic Primer For Non-Programmers

ActionScript is a scripting language similar to JavaScript that is used to add interactivity to Flash projects. It allows for reusable pieces of code called functions. Functions help organize code and make it more flexible by allowing sections of code to be executed from multiple places. Functions can accept parameters to make them more dynamic and return values. Understanding functions is an important part of learning ActionScript.

Uploaded by

user1230
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 27

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

Intermediate Flash with ActionScript 2


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

Intermediate Flash with ActionScript 3


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

Intermediate Flash with ActionScript 4


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.
Intermediate Flash with ActionScript 5
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

Intermediate Flash with ActionScript 6


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();

Intermediate Flash with ActionScript 7


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();

Intermediate Flash with ActionScript 8


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

Intermediate Flash with ActionScript 9


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

Intermediate Flash with ActionScript 10


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();
}

Intermediate Flash with ActionScript 11


Actions Panel

 Type as in a text-editing application


 When you use ActionScript 2.0 syntax you
get Strict Typing

Intermediate Flash with ActionScript 12


Flash MX 2004
ActionScript Categories

Intermediate Flash with ActionScript 13


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

Intermediate Flash with ActionScript 14


Functions

Intermediate Flash with ActionScript


Santa Rosa Junior College Jeffrey Diamond CIS 75.31A
Characteristics of Functions

 Functions hold other actions


 Allows you to control when functions are
executed when you call the function

Intermediate Flash with ActionScript 16


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.

Intermediate Flash with ActionScript 17


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

Intermediate Flash with ActionScript 18


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

Intermediate Flash with ActionScript 19


Running or invoking the function

 Simply proclaim the function’s name


(invocation)
on (release) {
functionName ();
}

Intermediate Flash with ActionScript 20


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();

Intermediate Flash with ActionScript 21


Passing information to functions

 Statements
 function moveBall(){
ball._x +=10;
ball._y +=10;
 }

Intermediate Flash with ActionScript 22


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

Intermediate Flash with ActionScript 23


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)
}

Intermediate Flash with ActionScript 24


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)

Intermediate Flash with ActionScript 25


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

Intermediate Flash with ActionScript 26


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

Intermediate Flash with ActionScript 27

You might also like