Skip to main content
Known Participant
February 21, 2010
Answered

duplicate movie clip

  • February 21, 2010
  • 1 reply
  • 978 views

hi, here is the deal. i asked an equivalent of 'duplicate movie clip' long ago, but i didnt use it though i knew i was going to use it in the future. the answer i got back then didn't work, i tried something else i found in another forum, here is what i tried:

create new empty flash project.

in this, at firt i imported a bitmap into stage and after converting it into movie clip, called it 'template'

what i think should happen is that a duplicate of the movie clip should appear in (0, 0). didn't work first way so i tried second way i found in another forum. this is all the code in the movie:

/*
var classObj: Object  = getDefinitionByName( getQualifiedClassName( this.template ) );

var newClassObj = new ( classObj );

newClassObj.x = 150;
newClassObj.y = 150;

this.addChild(newClassObj);
*/


var targetClass:Class = Object(template).constructor;
var duplicate:DisplayObject = new targetClass();

duplicate.visible = true;
duplicate.x=0;
duplicate.y=0;
addChild(duplicate);

things in /* */ are first way i got as answer some time ago, the things outside commenta re the new way i found in another forum. as i said before this should show on stage a duplicate of 'template', if it worked as expected. but it didnt in any case. any poinetrs?. i also tried with a doodle instead fo a bitmap with same result

This topic has been closed for replies.
Correct answer Ned Murphy

If you are going to manually add this movieclip to the stage, then you can just assign it a class id via the Linkage option for the symbol (similar to AS2's attachMovie linkage assignment) and just create a new instance of it. If you give it a class id of MyTemplate, then all you need to do is use

var duplicate:MyTemplate = new MyTemplate();

addChild(duplicate);

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
February 21, 2010

If you are going to manually add this movieclip to the stage, then you can just assign it a class id via the Linkage option for the symbol (similar to AS2's attachMovie linkage assignment) and just create a new instance of it. If you give it a class id of MyTemplate, then all you need to do is use

var duplicate:MyTemplate = new MyTemplate();

addChild(duplicate);

Known Participant
February 21, 2010

it worked that way, tnx! (still don't know why didnt work the other ways though)

Ned Murphy
Legend
February 21, 2010

You're welcome