attachMovie in AS3

Today I wrote a little replacement snippet for the deprecated attachMovie. The snippet has 3 parameters for the linkage name in the library, the name of the displayObject you wish to attach the MC to and an optional name param to identify it by name on the display list later on:


function attachMovieClip(mcName:String,target:MovieClip,newName:String="")
{
var mc=new (getDefinitionByName(mcName) as Class);
mc.name = newName;
target.addChild(mc);
}

along with Lee Brimelows very useful snippet panel for Flash CS4 attaching MovieClips from the Library at runtime is a bit less complicated especially for AS2 veterans ;-).

the xml snippet for the snippet panel is here for convenient copy/paste:

<snippet>
<title>attachMovie AS3</title>
<code><![CDATA[function attachMovieClip(mcName:String,target:MovieClip,newName:String="")
{
    var mc=new (getDefinitionByName(mcName) as Class);
    mc.name=newName;
    target.addChild(mc);
}]]></code>
</snippet>

Have fun!

Keine Kommentare:

Kommentar veröffentlichen

You might as well leave a comment on this matter: