Presentation is loading. Please wait.

Presentation is loading. Please wait.

Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.

Similar presentations


Presentation on theme: "Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip."— Presentation transcript:

1 Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip

2 Variables & Scope A variable's scope refers to the area in which the variable is known (defined) and can be referenced A variable's scope refers to the area in which the variable is known (defined) and can be referenced Global variables and functions are visible to every timeline and scope in your document. Therefore, a global variable is defined in all areas of your code Global variables and functions are visible to every timeline and scope in your document. Therefore, a global variable is defined in all areas of your code Timeline variables are available to any script on that timeline Timeline variables are available to any script on that timeline Local variables are available within the function body in which they are declared (delineated by curly braces) Local variables are available within the function body in which they are declared (delineated by curly braces)

3 Scope & Levels Main timeline: _level0 Main timeline: _level0 Each _levelX has it’s own timeline Each _levelX has it’s own timeline _root: The highest level (main stage) _root: The highest level (main stage) _parent: Up one level _parent: Up one level this: Current timeline this: Current timeline Tip! Large projects - many.swf files Tip! Large projects - many.swf files Loading of.swf files through: Loading of.swf files through:loadMovie() Loading to level 1: Loading to level 1: loadMovieNum("loadMovie1.swf", 1); Ex

4 Duplicate & levels Create a copy/copies of a movieClip Create a copy/copies of a movieClip Each movieClip copy need an unique level/depth (increase the level) Each movieClip copy need an unique level/depth (increase the level) Two general methods: duplicateMovieClip: MovieClip on stage duplicateMovieClip: MovieClip on stage duplicateMovieClip("newclip"+level, level); attachMovie: MovieClip from library (Linkage) attachMovie: MovieClip from library (Linkage) attachMovie("my_mc", "newclip"+level, level); Ex

5 duplicateMovieClip duplicateMovieClip: MovieClip on stage duplicateMovieClip: MovieClip on stage //duplicate first movieClip duplicateMovieClip("first_mc", "newclip" + level, level); //put new clips in position _root["newclip" + level]._x += xSpace; _root["newclip" + level]._y -= ySpace; //increase level level++; //increase the distance xSpace += 15; ySpace += 5; Ex

6 attachMovie attachMovie: MovieClip from library (Linkage) attachMovie: MovieClip from library (Linkage) //get the movieClip from library attachMovie("my_mc", "newclip"+level, level); //random position _root["newclip"+level]._x = random(470) + 50; //int(Math.random()*450 + 50); _root["newclip"+level]._y = random(250) + 50; //int(Math.random()*250 + 50); //increase level level++;//output clipName = "newclip" + level Ex

7 removeMovieClip A movieClip instance in a specific level/depth could be removed by the removeMovieClip function A movieClip instance in a specific level/depth could be removed by the removeMovieClip function _root["newclip"+ level].removeMovieClip(); Remove all/many movieClips by a loop Remove all/many movieClips by a loop for(i=0; i < length; i++){ _root.starMovie_mc["starText_mc" + i].removeMovieClip(this); } Ex


Download ppt "Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip."

Similar presentations


Ads by Google