Flash Exercise Notes 2
syllabus | schedule | assignments | class notes | web resources | ARTC courses
ActionScripting MovieClips
Levels and Depth


Layers in the timeline get converted to depths at runtime
Some MovieClip methods need to have a depth assigned
If you put something at the same depth as an existing item, it will erase the old one higher depth numbers are in front
Content added via code gets put in front of items in the timeline

Timeline Depths -16,384 to -1 (on the timeline - they can't be removed via code)
Dynamic 0 to 1048,575 (added via code - can remove via code)
Reserve 1,048,576 to 2,130,690,045 (can add via code but cannot remove them)


_level0 = main stage
_root = main stage
_parent = the parent of the clip you are in (this._parent.MCname._x)

this = the place where you are right now
Now a days people prefer to use "this" because if you import the MovieClip it will still work.
If you import a SWF with _root in the code then the code will have to be changed because the root level will have changed

Variable scope

To declare a global variable:
_global.variableName = 2;

To use a global variable:
myNum = variableName + 2;

You cannot use var in front of the declaration of a global
You cannot specify the type such as :Number or :String
Use globals sparingly - they take up valuable memory

Global variables are not accessible from within functions unless you say:
_global.VariableName each time you access it

Methods that act on MovieClips


MCName.createEmptyMovieClip(name:String, depth:Number):MovieClip

this.createEmptyMovieClip("container", this.getNextHighestDepth());


Makes copies of items in the library and puts them on the stage
Should set Linkage on the item in the Library
Right click - Linkage - Identifier (keep name) - Check Export for ActionScript - Export in first frame
Flash deletes all unused Library items before publishing - setting up Linkage saves it from being deleted.

MCname.attachMovie(id:String, name:String, depth:Number, [initObject:Object]):MovieClip
id = the linkage ID
name = the new name
initObject are the new parameters you want to set for the object

create1.onRelease = function() {
     var MCname:String = "BTack"+count;
     attachMovie("BlueTack", MCname, _level0.getNextHighestDepth(), {_x:400, _y:50});

duplicates a movieclip that is on the stage
The new one inherits the properties of the original.
You can change the parameters of the new MC with the initObject. the createNewMovieClip or attachMovie is used much more now a days.

MCname.duplicateMovieClip(name:String, depth:Number, [initObject:Object]):MovieClip

MCName.duplicateMovieClip("newClip", this.getNextHighestDepth(), {_x:50, _y:50});

duplicateButton.onRelease = function() {
     var newMC:String = "BTack"+dubCount;
     this._parent.redTackMaster.duplicateMovieClip(newMC, _level0.getNextHighestDepth(), {_x:200, _y:50, _rotation:145});


Removes a Movieclip that has been placed on the stage using attachMovie(), duplicateMovieClip(), or createEmptyMovieClip() - you can't remove clips that have been placed on the stage by dragging them out of the library.



This loads in files from the Internet or locally. It can load .jpg, .swf, .gif and .png files


this.createEmptyMovieClip("newMovieClip", this.getNextHighestDepth());



Removes external content that has been loaded using loadMovie()




Makes the movieclip follow the cursor - typically set on a onPress event and stopDrag is set on a onRelease()
The left, top, right and bottom restrict the movement of the object to an area.
To make it only go up and down, set right and left to the same number
To make it only go right and left, set the top and bottom to the same number

MCname.startDrag([lockCenter:Boolean], [left:Number], [top:Number], [right:Number], [bottom:Number]):Void

clip.onPress = function() {
clip.onRelease = function() {


Use with startDrag();


See if the movieclip's boundary box touches the bounding box of another movieclip

blueHit.onPress = function() {
blueHit.onRelease = function() {
     if (this.hitTest(hitBox)) {
     trace("you hit the spot");
     _root.warningBox.text = "Ouch!";
          _root.warningBox.text = "Put the blue tack in the box";


square_mc.hitArea = circle_mc;
square_mc.onRelease = function() {
     trace("touched it");

PROPERTIES of a MovieClip

_alpha Number transparency
_currentframe Number where the playhead is
_droptarget String path to the movieclip where a draggable clip was dropped on (read only)
_height Number height of the MC
_name String instance name of MC
_parent String MC that contains the MC you are in
_rotation Number the rotation of the MC
_target String path to MC relative main timeline (read only)
_totalframes Number total number of frames in MC
_url String gets address from which an SWF, JPG, GIF or PNG was loaded into the MC (read only)
_visible Boolean can you see it
_width Number width
_x Number x location
_xmouse Number x location of mouse relative to main timeline
_xscale Number percentage of the x scaling of the clip
_y Number y location
_ymouse Number y location of mouse relative to main timeline
_yscale Number percentage of the y scaling of the clip