Use the Same External Dynamic Image Infinitely

Use the Same External Dynamic Image Infinitely
Lauren Smith
Explorin Lauren is in fact the moniker for Lauren Smith. I am a Dallas native and a life-long (read: fair-weather) Cowboys fan. I enjoy being outside, when I am not working, and I love a strong cup of coffee, especially while working. I am also a full-time Interactive Developer for LevelTen Design based out of Dallas, TX. I spend most of my days deeply buried in work on Actionscript, CSS, XHTML, or the occasional XSLT and PHP.
View all articles by Lauren SmithFirst thing we need to do is import the BitmapData class
import flash.display.BitmapData;
This is simply a temporary movieclip that we will later remove altogether
_root.createEmptyMovieClip("tempMC", 1, {_alpha:0});These next several lines are simply setting up our MovieClipLoader
var theLoader:MovieClipLoader = new MovieClipLoader();
var theListener:Object = new Object();
theLoader.addListener(theListener);
This next line initiates our function as soon as the image has finished downloading and is ready to receive events
theListener.onLoadInit = function(mc:MovieClip) {
This creates a new BitmapData Object and then copies the image that we have loaded into that Object and finally removes the movieclip that we loaded our image into.
bitmapPic = new BitmapData(_root.tempMC._width, _root.tempMC._height);
bitmapPic.draw(mc);
_root.tempMC.removeMovieClip();
Now we will simply attach our BitmapData Object to a new movieclip, which you can do as many times as you want and we are finished.
_root.createEmptyMovieClip("picMC", 2);
_root.picMC.attachBitmap(bitmapPic, 3);
};
theLoader.loadClip("http://www.yourwebsitehere.com/yourimagenamehere.jpg", _root.tempMC);So that was relatively painless and can open up some new opportunities when using dynamically loaded images in Flash.
And for those that just want to copy and paste the code directly into Flash here you go...
import flash.display.BitmapData;
_root.createEmptyMovieClip("tempMC", 1, {_alpha:0});
var theLoader:MovieClipLoader = new MovieClipLoader();
var theListener:Object = new Object();
theLoader.addListener(theListener);
theListener.onLoadInit = function(mc:MovieClip) {
bitmapPic = new BitmapData(_root.tempMC._width, _root.tempMC._height);
bitmapPic.draw(mc);
_root.tempMC.removeMovieClip();
_root.createEmptyMovieClip("picMC", 2);
_root.picMC.attachBitmap(bitmapPic, 3);
};
theLoader.loadClip("http://www.yourwebsitehere.com/yourimagenamehere.jpg", _root.tempMC);Spread The Word
Related Articles
Related Links
4 Responses to "Use the Same External Dynamic Image Infinitely" 
|
said this on 08 Jun 2007 4:46:47 AM CDT
bitmapPic.draw(mc);
Should be : bitmapPic.draw(_root.tempMC) Or line 2 should be var mc = _root.createEmptyMovieClip("tempMC", 1, {_alpha:0}); |
|
said this on 03 Jul 2007 5:53:29 AM CDT
Eeeexcellent duude!
You saved me a LOT of time with this one. I spent almost a day trying to figure out why the heck duplicateMovieClip failed to duplicate!!! :))) |
|
said this on 12 Aug 2007 7:38:54 PM CDT
It works fine, until I use theLoader.duplicateMovieClip() or try to copy some area of the image. Some ideas what went wrong?
|
|
said this on 15 Nov 2007 2:03:13 PM CDT
notice that in order to copy the JPG/GIF/PNG file inside the movie clip, you will need to store the BitmapData object, and use the draw method each time you duplicate the movie
|



Author/Admin)