开发者

Duplicating an imported graphic in Flash

开发者 https://www.devze.com 2022-12-17 18:50 出处:网络
I\'m loading a graphic via the开发者_如何学JAVA 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 t

I'm loading a graphic via the开发者_如何学JAVA 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?


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;


Depending on what you need to do with it you have three options.

  1. Load it again. By far the easiest, it's going to be cached anyway so you won't need to hit the server twice.
  2. Use BitmapData.draw(). Create a bitmapdata and draw your loader to it, also pretty easy, but you can't do any animation without having to redraw.
  3. Load it and wrangle out the class of your graphic (only applies to .swf's) and use that to instantiate copies. Take a look at getDefinitionByName. This is a little bit tricky since you are at the mercy of the sandbox, but it's also the most proper way to do it.
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号