Search code examples
flashactionscript-3imageduplication

Duplicating an imported graphic in Flash


I'm loading a graphic via the Loader Class. Now I need to use it both as the original image and a thumbnail of that image. Alas, there is no "duplicateMovieClip" or anything like that in AS3

If I addChild it to the normal view and then to the thumbnail only the thumbnail is shown and vice versa.

I google for this and found several solutions online, but they all just seem to work with Images from the library and not loaded from a Server.

So, how do I do this without having to load the Image twice?


Solution

  • If were are just talking about a bitmap image, the simplest thing is just to share the BitmapData with another Bitmap instance. See below:

    var existingBitmap:Bitmap; //which you have from the loader
    var thumbNail:Bitmap = new Bitmpap(existingBitmap.bitmapData);
    
    thumbNail.witdth = 64;
    thumbNail.height = 64;
    
    addChild(thumbNail);
    

    Since you are using a loader, you can access the bitmap image you loaded externally through the content property.

    var existingBitmap:Bitmap = myLoader.content;