as3

Duplicate an Object in Flash

I'm working on a tile editor in Flash CS4 and opted to use the TileList class for the palette. Once a swatch is selected, I need to create a copy of that swatch and attach it to the stage. I wasn't quite sure how polymorphism in AS3 worked but I ended up with this little snippet:

var mySwatchClass:Class = mySwatch.source.constructor;
var newTile = new mySwatchClass();

Let me know if it helps!

Syndicate content