313 flash lecture n.
Skip this Video
Loading SlideShow in 5 Seconds..
313 Flash Lecture PowerPoint Presentation
Download Presentation
313 Flash Lecture

Loading in 2 Seconds...

play fullscreen
1 / 26

313 Flash Lecture - PowerPoint PPT Presentation

  • Uploaded on

313 Flash Lecture. Lecture Three. Scripts on Frames vs. Buttons. what is the difference between the two? let’s write a goto on a frame script gotoAndStop("section1"); lets write a button event (when we press it) that takes us to a frame label on(release) { gotoAndStop(“framelabelname”); }.

I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
Download Presentation

PowerPoint Slideshow about '313 Flash Lecture' - gabriel-cardenas

An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.

- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
313 flash lecture

313 Flash Lecture

Lecture Three

scripts on frames vs buttons
Scripts on Frames vs. Buttons
  • what is the difference between the two?
  • let’s write a goto on a frame script


  • lets write a button event (when we press it) that takes us to a frame label

on(release) {



conditionals if
Conditionals (if)

These are the gateways to creating smart and intelligent Flash movies.

If (currentProfessor == “overlydemanding” {

trace (“What did I do to deserve this?);


If (this condition is met) {

then execute this statement


  • The repeating of the tedious tasks that we don’t want to do!
  • How could we get the computer to output a list of numbers from 1 through 5?
  • You already know one simple way?
loop trace
Loop (trace)

trace (1);

trace (2);

trace (3);

trace (4);

trace (5);

But what if we want the series to start at 100? There must be an easier way!

loop trace with variable
Loop (trace) with variable

var x = 1;


what do you think would come next to get to two?

x = x + 1;


if we change the starting number when we assign x to 100 it will now count up from 100 without changing five numbers, we only change one.

what if we wanted to count to 1000?

the while loop
the while loop

var x = 1;

while (x <= 5) {

trace (x);

x = x + 1;



Functions allow us to create little sections of modular code.

We use them already gotoAndPlay

We can also make/define our own.

function area(height, width) {

return height * width;


Functions take arguments and return information.

variables continued
Variables continued…
  • to create a new variable we use the var statement
  • one of the best places to do this is in an init script at the beginning of your movie (normally after a pre-loader)
  • var whatever;
  • var nameof book;
  • var x;
legal variable names
Legal Variable Names
  • may only contain letters, numbers, dollar signs and under-scores
  • must start with a letter or underscore or a dollar sign
  • are case-insensitive
  • you should add suffixes to your variable names, as well
    • var firstName_str;
    • var products_array;
code hints
_mc MovieClip

_array Array

_str String

_btn Button

_txt Text Field

_sound Sound

_color Color

_video Video

Code hints
assignment order
Assignment Order

variable assignment works from right to left

variableName = value;

simple example

speed = 100;

complex example

x = x + 1

vs operator
= vs. == operator

if (speed = 100) { //changes the value of speed

if (speed == 100) { //does a comparison

= sets a value

== compares a value

variable typing strict vs automatic
Variable TypingStrict vs. Automatic

Most programming languages require that we tell a variable what type of datum it can accept. Actionscript 2.0 allows for automatic typing, although it is being discouraged. Let’s put this in frame one.

var firstName;

firstName = “Jim”;

firstName = “Daisy”;

trace (firstName)

variable scope where it all breaks down
Variable Scope(where it all breaks down…)
  • Flash is very picky in wanting to know what is being executed where. You have to let it know where variables exist. There are several strategies used to achieve the communication you desire among your Flash minions.
  • Let’s do a little experiment.
variable scope cont
Variable Scope cont.

go to frame two of the main timeline

var x;

x = 10;

go to frame three of the main timeline


test the movie, what happens?

variable scope cont1
Variable Scope cont.

get rid of the code on frames two and three

go to frame thirty of the main timeline

var x;

x = 10;


go to frame fifteen of the main timeline

trace (x);

test the movie, what happens and why?

global vs local
Global vs Local
  • Variables that can be accessed throughout the program are called global variables.
  • Variables that are accessible only to limited sections of the program are called local variables.
  • In Flash, all variables must be scoped to one of the following;
    • A function (local timeline)
    • The main timeline or movie clip (timeline variable)
    • The _global object (global variable)
variables on different timelines
Variables on different timelines

create two different shapes (square, circle) and define them as movie clip symbols

on frame 1 of square set x to 3

var x;

x = 3;

on frame 1 of circle set y to 4

var y;

y = 4;

place instances of the clips on frame 1 layer 1 of the main timeline and name the instances square and circle

on frame 1 of the main timeline enter the following frame script

trace (x);

trace (y);

test the movie, what happens?


scope crash
Scope Crash!
  • Variables attached to a movie clip timeline have scope limited to that timeline. they are not directly accessible to scripts on other timelines, such as our main movie timeline.
  • What if we place the trace(x) and trace(y) statements on frame 1 of the square movie clip
  • Comment out the trace commands on the main timeline with // at the beginning of the line. That will leave the code, but the flash interpreter will ignore it


accessing variables on different timelines from the main timeline
Accessing Variables on Different Timelines from the main timeline
  • They are not directly accessible, but can be accessed indirectly using dot syntax.
    • movieClipInstanceName.variableName
  • If we refer to a variable on another timeline we must use the name of the movie clip to get there. For example, if we are in main timeline and want to get to the variables in our circle and square movie clips, how would we get there?



This is known as a qualified reference.

some gotcha s
Some gotcha’s
  • make sure that you have named your movie clips with instance names
  • make sure that your movie clips are persistent on the stage. If you have a keyframe on the main timeline, the variables will be lost.
  • you have to make sure that the variable has been created in the movie clip before you call on it in the main timeline. ex. if you declare the variable in frame one of the movie clip it is not accessible until frame two of the main timeline
accessing variables on different timelines cont
Accessing Variables on Different Timelines (cont.)
  • To get access a variable from square while inside the circle timeline. We need to use an absolute reference.
  • If we are in circle, we can get to square’s x variable.


This command will work anywhere in our movie.

Let’s comment out the trace command in frame one of the main timeline and add a trace in circle that gets to square’s x value.

we can also move relatively between clips
We can also move relatively between clips.

by using the _parent.myVariable syntax we can go up in the timeline.

this refers to the variables on the timeline above the location you are calling it from

create a new flash file

go to frame one of the main timeline and type

var x;

x = 10;

create another movie clip symbol and put it on the timeline. Go to frame one on the timeline of that movie clip.


test the movie

let s try a global variable
Let’s try a global variable

Go to frame 1 of the square movie

_global.day = “Wednesday”;

Go to frame 1 of the main timeline

trace (day);

Test the movie

Go to frame 1 of the circle movie

var day = “Friday”;

trace (day);

Test the movie, which variable has precedence?