Internet Marketing
Traditional Marketing
Corporate Branding
SEO Services
Designing Tutorials
Flash Action Scripting Tutorials
Workshop Objectives
By the end of the workshop, you should be able to:
- Add scripts to frames, buttons, and movie clips
- Use variables to control aspects of a movie
- Use variables to control “dynamic text”
Using Scripts in an Object-Oriented Environment like Flash
- Where do you put the scripts? Flash is object-oriented; scripts can be attached to almost any object:
- Frames, movie clips, buttons, lots more
- Scripts are activated when an “event” occurs
- A frame is played
- A button is pressed
- A movie clip is loaded
Using Buttons
- Understanding the syntax of “Event Handlers”
on (release) {
gotoAndPlay(1);
} - In English…
On the event of “release of the mouse button”, do whatever is between the {}, in this case, go to frame 1 and begin playing. - Other button events
press, release, releaseOutside, rollOver, rollOut, dragOver, dragOut, keyPress "<Space>"
Some Good Rules and Hints
- Use the code hints
- Take note of script colorization
- Use the “Check Syntax” and “Auto format” buttons frequently at the start
- Rules for typing action commands
First word is lowercase, remaining words begin with uppercase
Examples: gotoAndPlay, gotoAndStop, stopAllSounds
Advice: Use this convention when naming your own variables and functions
- Type both {} at each new handler or condition
- Right click on an action to get to the reference section
Variables
- Types of variables
- Numeric
- Integers and floating point numbers
- Integers and floating point numbers
- Strings
- A sequence of characters
- Numeric
- Local and Global Variables
- Global variables are accessible throughout the Flash movie
- Local variables are stored in objects and only accessible by that object
- You can have two local variables with the same name if they are in separate objects
- You can only have one global variable with the same name.
- Global variables are accessible throughout the Flash movie
Parts of a Script
on (press) { |
![]() |
![]() |
Syntax: Comparisons & Operators
| = | Used to assign |
| == | Used to compare |
| != | Means “not equal” |
on (release) {
a = 7;
trace(a == 8);
False
trace(a == 7);
True
trace(a != 7);
True
}
on (release) {
a = 7;
trace(a < 8);
False
trace(a > 6);
False
trace(a < 1);
False
}
Operators
Two equivalent ways to increase a variable by a certain amount.
on (release) {
a = 7;
a = a + 4;
trace(a);
11
a += 5;
trace(a);
16
trace(++a);
17
}
Increments a variable by 1. Other ways:
a = a + 1;
a += 1;
Syntax: Conditions
The if Statement
if (a == 7) {
gotoAndPlay(2);
}
Other Instructions: gotoAndPlay(1); gotoAndPlay("abc"); nextFrame(); prevFrame(); nextScene(); prevScene(); gotoAndStop("Scene Name", "");
The if and else Statements
on (release) {
a = 7;
if (a == 7) {
trace(“Yes, it’s 7”);
} else {
trace(“No, not 7”);
}
}
Loading Variables
From External File
var nameVars = new LoadVars();
nameVars.onLoad = function(ok) {
if (ok) {
text_first = nameVars.firstname;
text_last = nameVars.lastname;
}
};
nameVars.load("textfile.txt");
Note: ‘text_first’, ‘text_last’ are dynamic text fields in Flash.
Create “textfile.txt” file with this text
firstname=Subramanyam&lastname=Inkollu&r=50&g=200&b=50
Setting the RGB Colors
To MovieClip Instance
- Create a movie clip with the instance name of “myShirt”
- Write the below script in frame.
myColor = new Color(_root.myShirt);
myColor.setRGB(0x003399);
If you are using Button
on (release) {
myColor.setRGB(0x003399);
}
Loading RGB Values as Variables
myColor = new Color(_root.myShirt);
myDesign = new Color(_root.myDesign);
var nameVars = new LoadVars();
nameVars.onLoad = function(ok) {
if (ok) {
myColor.setRGB(nameVars.selectedColor);
myDesign.setRGB(nameVars.designColor);
}
};
nameVars.load("textfile.txt");
Note: ‘myShirt’, ‘myDesign’ are instances of movie clips
Create “textfile.txt” file with this text
selectedColor=0x66CCFF&designColor=0xFF9900






