There’re a lot of difficult ways I’ve seen online to duplicateMovieClip in AS3, when it can actually be quite easy: make the clip you wish to duplicate a class. Right-click on it in the library and export it as a class.
Then when you want to duplicate it, just create a new movieclip that is a class of that clip you wish to duplicate.
Eg below. I created a class, ‘scrollerContentMC’ which I wanted to duplicate within the shell clip contentMC. I have the first page already there, ‘page0’, just for placement use. Then the lot are added to the ‘page’ array so I can reference them easily through that.
// adding fisrt item to the page array (page0); page.push(contentMC.page0); var numPages:Number = contentMC.page0.totalFrames; for(var i:uint = 1; i < numPages; i++) { // -1 cause we've already got page0 on the stage var tempPage:scrollerContentMC = new scrollerContentMC; contentMC.addChild(tempPage); page.push(contentMC.getChildAt(i)); // adding the new items to the page array. So we can only refer to the clips through array. }
Leave a Reply