 |
|
 |
 |
 |
Show off your stuff with a
Quick Project
|
 |
Build a Flash movie that shows off your knowledge of Flash animation
Due next Monday, at start of class |
 |
 |
 |
 |
|
 |
 |
 |
Great Book
|
 |
Moock, Colin
ActionScript: The Definitive Guide, Second Edition
O'Reilly Publishing, 2003 |
 |
 |
 |
 |
|
 |
 |
 |
EMAIL
EMAIL
EMAIL
|
 |
Gimme! Only four so far, must have by next class.
|
 |
 |
 |
Who's in
|
 |
Not looking to good...
|
 |
 |
 |
 |
|
 |
 |
 |
What is a Script?
|
 |
Think of a motion picture. A script tells everyone in the movie what to do.
|
 |
 |
 |
What is an Action?
|
 |
Action = Command
Stop
Start again
Go somewhere and
play from there
A way of talking to the "engine" |
 |
 |
 |
Where do ActionScripts live?
|
 |
In frames and movieClips.
They can't survive on their own.
|
 |
 |
 |
Who do ActionScripts direct?
|
 |
The playback head
movieClips
Each other
Among other things...
|
 |
 |
 |
How do you build them?
|
 |
In the Actions Panel
|
 |
 |
 |
 |
|
 |
 |
 |
How to access it
|
 |
Menu
Properties Panel
F9
|
 |
 |
 |
What's in it?
|
 |
Let's see...
Action assignment menu/status
Watch out -- a GOTCHA!
Actions tree panel
Script Pane
Icons
Add Actions menu
Reference
View Options
Window menu
Skip the others for now...
|
 |
 |
 |
Ala mode
|
 |
Use Expert Mode!
View line numbers
|
 |
 |
 |
 |
|
 |
 |
 |
Simple Variables
|
 |
With the first frame selected:
var message = "hi there, Flash";
var firstName = "James";
trace(message);
|
 |
 |
 |
Do an operation
|
 |
As above, but try this:
trace("hi there, " + firstName + ", nice to meet you.";
|
 |
 |
 |
Keeping track of things with variables
|
 |
A variable has a name:
firstName
A variable has a value:
"James"
Values can be text (strings) or numbers
Assign a value to a variable like this:
var firstName = "James"
|
 |
 |
 |
Arguments
|
 |
AKA parameters
command(argument);
trace(firstName);
You can pass multiple arguments:
command(argument1, argument2, argument3);
|
 |
 |
 |
Operators
(a few)
|
 |
A statement that operates or acts on something else.
|
 |
 |
 |
Expressions
|
 |
Any segment of code that yields a single piece of data
7
"this is a string"
variables
9 * 12
messageVariable + " How are you?"
(2 + 3) * (4 / 2.5) - 1
Handy nomenclature when you need to say things like:
"To assign a value to a variable, type the name of the variable, then an equal sign followed by any expression"
|
 |
 |
 |
Conditionals
|
 |
Statements of logic that determine what to do when a specific criteria is met, or is not met.
if/then
var firstName = "James"
if (firstName == "James") {
trace("firstName was James");
}
if/then/else
var firstName = "Bob"
if (firstName == "James") {
trace("firstName was James");
} else {
trace("firstName wasn't James");
}
if/then/else if/else
var firstName = "Jane"
if (firstName == "James") {
trace("firstName was James");
} else if (firstName == "Bob"){
trace("firstName was Bob");
} else {
trace("it wasn't Bob or James");
}
|
 |
 |
 |
Loops
|
 |
Statements of logic that repeat until a condition is true
while
while(this condition is true) {
do this statement over and over
until it is true;
}
var counter = 1;
while(counter < 5) {
counter = counter + 1;
// or counter =+ 1 or counter ++
trace(counter);
}
Output window says:
1
2
3
4
5
|
 |
 |
 |
Comments
|
 |
A string of text that is not executed as part of the script.
// This sets off a comment until you hit return
Good Habit #1: COMENT YOUR CODE AS YOU GO ALONG!
|
 |
 |
 |
 |
|
 |
 |
 |
One
|
 |
Create a script in frame 1 that will output the phrase...
"Hi, my name is (whatever your name is, stored in
a variable), how are you?"
...in the trace window. Watch out for spaces around the variable value output.
|
 |
 |
 |
Two
|
 |
Create a script in frame 1 that sets a variable to your first name.
Then test that variable in an if/then statement so that it outputs...
"Yes, that is my name"
...if the variable is the same as your name, and outputs...
"No, that's not my name"
...if it isn't.
|
 |
 |
 |
Advanced One
|
 |
Create a script in frame 1 that will output...
"The sum of 3 + 9 is 12"
...using variables in place of 3 and 9 and using operators to output the sum.
|
 |
 |
 |
Advanced Two
|
 |
Create a script in frame 1 that uses a while statement to output these numbers:
"4, 16, 256, 65536"
|
 |
 |
 |
 |
 |
 |
 |