Jump to content
Search Community

Two images using one data from ImageLoader issue[Solved]

noob test
Moderator Tag

Recommended Posts

Sup, guys.

I am kinda new to AS3, so my problem might be a dumb one, but anyway.

 

So i am loading some image, using ImageLoader like this:

var fire:ImageLoader = new ImageLoader(E:/AS3/Projects/Island/fire.png", {name:"fire", onComplete:onImageLoad});
fire.load();

 

Then in the onImageLoad handler i create two bitmaps using loaded data:

private function onImageLoad(event:LoaderEvent):void {
var smt:Bitmap = LoaderMax.getLoader("fire").rawContent;
addChild(smt);

var ant:Bitmap = LoaderMax.getLoader("fire").rawContent;
addChild(ant);
  ant.x = 200;

 

Then i compile my swf and there is only one image on the stage. Also, if i remove one of the images (ant or smt) using removeChild(), the stage becomes clear as if both bitmaps just point to one instance. This is driving me insane for a couple of hours. What am i doing wrong?

Link to comment
Share on other sites

The ImageLoader's rawContent refers to a Bitmap object which can only exist in one place at a time (just like any DisplayObject). You can, however, create another Bitmap object and use the same BitmapData like this:

 

private function onImageLoad(event:LoaderEvent):void {
  var bd:BitmapData = LoaderMax.getLoader("fire").rawContent.bitmapData;
  var smt:Bitmap = new Bitmap(bd);
  addChild(smt);

  var ant:Bitmap = new Bitmap(bd);
  addChild(ant);
  ant.x = 200;
}

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...