FLASH 8 and CS3. Action Scripting 2.0

Alejandra Jarabo
MAT 116

Media Arts & Technologies division. Santa Barbara City College
ACTION SCRIPTING SPECIFICS

DOT SYNTAX

Dot Syntax is a formatting convention to create quick and efficient phrases that refer to buttons, movie clips and other objects.

The “dot” • is used to indicate the properties or methods related to an object (there is no space in between the elements and the dot)

   

Ball_mc • stop ( ) ;
_______•________
  WHO      WHAT

WHO: is the INSTANCE NAME of your button or movie*.

WHAT: The Action that you want it to do/ The property that you want to reset/ The Method to apply

   ;   or semicolon marks the end of a statement (just like period marks the end of a sentence)

     

Ball_mc• gotoAndStop (5) ;
________•_________________
  WHO      WHAT                

METHODS are special pieces of script (they are based on Functions)
that use a parenthesis to hold the parameters (called in Flash Arguments

If I add "gotoAndStop" I need to ADD Where do I want to go, this is the part of the script that varies on each case. So, gotoAndStop(5) is an Action that has been constructed as a Method.
The frame number in this case is the parameter, and it is contained in the parenthesis.

Some Methods don't need Arguments to work, that is the case of:
stop()
play()
nextFrame()
nextScene()

     

Ball_mc• _x=50 ;
________•________
  WHO      WHAT  


Ball_mc• _alpha=30 ;
_______•___________
  WHO      WHAT    


square_btn•_width = 200;

square_btn•_height = 200;  

square_btn•_visible = true;

square_btn•_visible = false;  
 

OBJECTS have PROPERTIES that can be reset with Action Scripting 2.0:

_x   Sets the horizontal position of an object in relation with the Stage origin (the left upper corner).
_y   Sets the vertical position of an object in relation with the Stage origin (the left upper corner).

_xscale   Sets the value specifying the percentage for horizontally scaling a button instance.
_yscale   Sets the value specifying the percentage for vertically scaling a button instance.

_rotation   Sets the the rotation of the button, in degrees, from its original orientation.
_alpha  Sets the the alpha transparency value of the button specified (from 0 to 100).

_height   Sets the height of the button, in pixels.
_width  Sets the width of the button, in pixels.

_visible   Sets a Boolean value that indicates whether the button specified is visible. Buttons that are not visible (_visible property set to false) are disabled: they don't work when they are not visible.

enabled   Sets a Boolean value that specifies whether a button is enabled. The default value is true.

 

* the Upper-Left coordinates of the Stage are (0,0)
If the object is inside of a Movie-clip the _x and _y properties set the coordinates in relation to the local coordinates of the parent movie clip. The button's coordinates refer to the registration point position.

     
   
WHY NAMING A SYMBOL'S INSTANCE ON STAGE

In Flash you can program an action in DOT SYNTAX referred to a MOVIECLIP'S instance or refered to a BUTTON'S instance.

In both cases you will have to name the instance on Stage through the Properties Panel before you write the code.
The name of the symbol in the Library is irrelevant for this matter. If you don't name it through the Properties Panel it will have no name.

The reason for this is that you might have created several copies of the same symbol, in the same project, on the same frame. If you didn't name them on Stage, Flash wouldn't know which one of them has to perform the action.

It is a good idea to name instances through this naming convention:
Button-instances should be named : "something_btn", so later on, when looking at the code, you easily recognize that the object is a button.
Movieclip-instances are usually named : "something_mc", so looking at the code, you can recognize it as the name of a movieclip.


If you look up to previous example on this page, the script will not work if you hadn't named the button "Square_btn", and the movie "Ball_mc" in the Properties panel of the project.

 
CALLING A BUTTON FROM A FRAME_ACTION

We are going to see next how to write the Action Script for your buttons, inside a frame-action.

Because the piece of script is going to be "living in a Frame", we need to specify which action refers to which button. In order to do that we will use Dot syntax to build the script.

HOW TO NAME AN OBJECT (an instance of a symbol on Stage)

When you use a symbol in your project you place an instance of the symbol on Stage. We call it an object.

The First thing we need to do when we want to use Dot Syntax is to give a name to each one of the objects that are going to BE CALLED by a script.
If we are going to add a Timeline-Action to one or several buttons, we need to give them names independent of their name in the Library
(remember: the name in the Library doesn't count as a name in the Stage).

To do so, select the button, go to the Properties panel, and write a name in the Text-field underneath the word "button".
(before we named frames, now we are naming buttons. It is a similar procedure, as you see).

We are going to follow a naming convention to make our lives easier (for when we have to debug problematic scripting), please get used to name your buttons as:
name_btn, later on you will name your movies like that: name_mc.
This way you will be able to differentiate them visually in the Action Scripting window.

THE SCRIPT IN ACTION SCRIPTING 2.0

B1_btn • onPress=function() {
gotoAndStop(5);
}

on(press) {
gotoAndStop(5);
}

 
This is the dot syntax for an action attached to a keyframe
placed in the "ACTIONS" layer

This is the default syntax for an action attached to a button named B1_btn in AS 2.0

   

Example of Dot syntax in the Actions Panel. Notice the selected Keyframe in the 'ACTIONS' layer.

 
   
 
la
 
     
     

Play first
with Rollover,

Then experiment with Press and Rollover