Instantiate class from loaded xml image (workaround)

Background: I needed to duplicate an image loaded into the Flash movie with XML. What I wanted to do was to create a new class of that MovieClip so that creating multiple instances of that MovieClip/Sprite wouldn’t be a problem, but I couldn’t get it working without external ActionScript class files (felt like too much hassle for a small project like this). I’ll continue on this code though when there is more time and hopefully follow up on it. Though maybe a solution like that, creating a new class instance of a loaded image, would be resource heavy for the Flash Player. I don’t know.

Anyway, here’s what I did:

var bigTickMarkBitmap:Bitmap;
 
bigTickMarkBitmap = e.target.loader.content as Bitmap;

I’m using the loader class to read the data and create a new Bitmap. Then, when I want to create multiple instances of this, I do the following:

for(var i:int=0; i<10; i++) {
var tmp:Bitmap = new Bitmap();
tmp.bitmapData = bigTickMarkBitmap.bitmapData; // this duplicates the bitmap data from the loaded bitmap
 
var bigTick:MovieClip = new MovieClip();
bigTick.addChild(tmp);
tickMarkContainer.addChild(bigTick);
}

I also tried code like this, but with no luck:

var SomeClass:Class = Class(getDefinitionByName("bigTickMarkBitmap"));
var obj:Object = new SomeClass();
 
var sprite:DisplayObject = target.addChild(DisplayObject(obj));
 
return Sprite(sprite);

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="">