Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.
-
Upload
barry-french -
Category
Documents
-
view
214 -
download
0
Transcript of Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.
![Page 1: Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.](https://reader036.fdocuments.us/reader036/viewer/2022082713/5697bff41a28abf838cbd3ba/html5/thumbnails/1.jpg)
Flash ActionScriptFlash ActionScriptIntroduction toIntroduction to
Scope & Levels Scope & Levels duplicateMovieClip & duplicateMovieClip &
attachMovieClipattachMovieClip
![Page 2: Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.](https://reader036.fdocuments.us/reader036/viewer/2022082713/5697bff41a28abf838cbd3ba/html5/thumbnails/2.jpg)
Variables & ScopeVariables & Scope A variable's A variable's scopescope refers to the area in which the refers to the area in which the
variable is known (defined) and can be referencedvariable is known (defined) and can be referenced
Global variablesGlobal variables and functions are visible to every and functions are visible to every timeline and scope in your document. Therefore, a timeline and scope in your document. Therefore, a global variable is defined in all areas of your code global variable is defined in all areas of your code
Timeline variablesTimeline variables are available to any script on are available to any script on that timelinethat timeline
Local variablesLocal variables are available within the function are available within the function body in which they are declared (delineated by curly body in which they are declared (delineated by curly braces) braces)
![Page 3: Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.](https://reader036.fdocuments.us/reader036/viewer/2022082713/5697bff41a28abf838cbd3ba/html5/thumbnails/3.jpg)
Scope & LevelsScope & Levels Main timeline: _level0 Main timeline: _level0 Each _levelX has it’s own timelineEach _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 timelinethis: Current timeline Tip! Large projects - many .swf filesTip! Large projects - many .swf files
Loading of .swf files through:Loading of .swf files through:loadMovie()loadMovie()
Loading to level 1:Loading to level 1:loadMovieNum("loadMovie1.swf", 1);loadMovieNum("loadMovie1.swf", 1);
Ex
![Page 4: Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.](https://reader036.fdocuments.us/reader036/viewer/2022082713/5697bff41a28abf838cbd3ba/html5/thumbnails/4.jpg)
Duplicate & levelsDuplicate & levels Create a copy/copies of a movieClip Create a copy/copies of a movieClip Each movieClip copy need an unique level/depth Each movieClip copy need an unique level/depth
(increase the level) (increase the level)
Two general methods:Two general methods: duplicateMovieClip: duplicateMovieClip: MovieClip on stageMovieClip on stage
duplicateMovieClip("newclip"+level, level);duplicateMovieClip("newclip"+level, level);
attachMovie: attachMovie: MovieClip from library (Linkage)MovieClip from library (Linkage)attachMovie("my_mc", "newclip"+level, level);attachMovie("my_mc", "newclip"+level, level);
Ex
![Page 5: Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.](https://reader036.fdocuments.us/reader036/viewer/2022082713/5697bff41a28abf838cbd3ba/html5/thumbnails/5.jpg)
duplicateMovieClipduplicateMovieClip duplicateMovieClip: duplicateMovieClip: MovieClip on stageMovieClip on stage
//duplicate first movieClip//duplicate first movieClipduplicateMovieClip("first_mc", "newclip" + level, level);duplicateMovieClip("first_mc", "newclip" + level, level);
//put new clips in position//put new clips in position_root["newclip" + level]._x += xSpace;_root["newclip" + level]._x += xSpace;_root["newclip" + level]._y -= ySpace;_root["newclip" + level]._y -= ySpace;
//increase level//increase levellevel++;level++;
//increase the distance//increase the distancexSpace += 15;xSpace += 15;ySpace += 5;ySpace += 5;
Ex
![Page 6: Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.](https://reader036.fdocuments.us/reader036/viewer/2022082713/5697bff41a28abf838cbd3ba/html5/thumbnails/6.jpg)
attachMovieattachMovie attachMovie: attachMovie: MovieClip from library (Linkage)MovieClip from library (Linkage)
//get the movieClip from library//get the movieClip from libraryattachMovie("my_mc", "newclip"+level, level); attachMovie("my_mc", "newclip"+level, level);
//random position//random position_root["newclip"+level]._x = random(470) + 50; _root["newclip"+level]._x = random(470) + 50; //int(Math.random()*450 + 50);//int(Math.random()*450 + 50);_root["newclip"+level]._y = random(250) + 50; _root["newclip"+level]._y = random(250) + 50; //int(Math.random()*250 + 50);//int(Math.random()*250 + 50);
//increase level//increase levellevel++;level++;
//output//outputclipName = "newclip" + levelclipName = "newclip" + level
Ex
![Page 7: Flash ActionScript Introduction to Scope & Levels duplicateMovieClip & attachMovieClip.](https://reader036.fdocuments.us/reader036/viewer/2022082713/5697bff41a28abf838cbd3ba/html5/thumbnails/7.jpg)
removeMovieClipremoveMovieClip A movieClip instance in a specific level/depth could A movieClip instance in a specific level/depth could
be removed by thebe removed by the removeMovieClip functionremoveMovieClip function
_root["newclip"+ level].removeMovieClip();_root["newclip"+ level].removeMovieClip();
Remove all/many movieClips by a loopRemove all/many movieClips by a loop
for(i=0; i < length; i++){for(i=0; i < length; i++){
_root.starMovie_mc["starText_mc" + i].removeMovieClip(this);_root.starMovie_mc["starText_mc" + i].removeMovieClip(this);
}}
Ex