Accessibility

ActionScript cookbook beta

Dynamically attach a MovieClip from the library

Problem Summary

You need to dynamically attach a MovieClip from the library.

Solution Summary

Use the MovieClip constructor to attach a symbol from the library.

Explanation

ActionScript 2

attachMovie("my_clip", "clip", 10);

clip._x = 100;
clip._y = 100;
clip._alpha = 50;

ActionScript 3

var clip:MovieClip = new my_clip();

clip.x = 100;
clip.y = 100;
clip.alpha = .5;

addChild(clip);

Note: In ActionScript 2 the linkage ID, "my_clip", is set in the library for the MovieClip, whereas in ActionScript 3, the class name, "my_clip", is set.