Learning ActionScript 2.0 in Adobe Flash |
|
|
|
| Working with Movie Clips > Adding parameters to dynamically created movie clips | |||
When you use MovieClip.attachMovie() and MovieClip.duplicateMovie() to create or duplicate a movie clip dynamically, you can populate the movie clip with parameters from another object. The initObject parameter of attachMovie() and duplicateMovie() allows dynamically created movie clips to receive clip parameters.
For more information, see attachMovie (MovieClip.attachMovie method) and duplicateMovieClip (MovieClip.duplicateMovieClip method) in the ActionScript 2.0 Language Reference.
To populate a dynamically created movie clip with parameters from a specified object:Do one of the following:
attachMovie():
myMovieClip.attachMovie(idName,newName,depth[,initObject]);
duplicateMovie():
myMovieClip.duplicateMovie(idName,newName,depth[,initObject]);
The initObject parameter specifies the name of the object whose parameters you want to use to populate the dynamically created movie clip.
To populate a movie clip with parameters by using attachMovie(): Make sure this text field is below and to the right of the registration point.
name_str, and assign its value to the text property of name_txt, as shown in the following example:
var name_str:String; name_txt.text = name_str;
The Linkage Properties dialog box appears.
/* Attaches a new movie clip and moves it to an x and y coordinate of 50 */
this.attachMovie("dynamic_id", "newClip_mc", 99, {name_str:"Erick", _x:50, _y:50});
The name you specified in the attachMovie() call appears inside the new movie clip's text field.
For a sample source file, gallery_tween.fla, that provides an example of how to use ActionScript to control movie clips dynamically while loading image files into a SWF file, which includes making each movie clip draggable, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and navigate to the ActionScript2.0/Galleries folder to access the sample.
For a sample source file, animation.fla, that creates and removes numerous movie clips at runtime, see the Flash Samples page at www.adobe.com/go/learn_fl_samples. Download and decompress the Samples zip file and navigate to the ActionScript2.0/Animation folder to access the sample.
|
|
|
|