Converting bitmapdisplay object to sprite (Please help)

Hi

I am loading jpg image and then trying to assign that image to a sprite object

I have a class that is loading the image and it has a method that returns the loaded image this class is called ImageLoader and the code that loads and returns the image is given under


//ImageLoader class
private var loadedImage:Object;
 
public function loadImage(image:String):void
  {
   urlRequest = new URLRequest(image);
   loader.contentLoaderInfo.addEventListener(Event.INIT, initListener);
   loader.load(urlRequest);
  }
  public function initListener(e:Event):void
  {
   loadedImage = new Object();
   loadedImage = loader.content;
   dispatchEvent(new Event(Event.COMPLETE));
  }
  public function getImage():Object
  {
   return loadedImage;
  }
 

I have another class content that calls the getImage method of ImageLoader when the complete event is dispatched the code from that class is given under


//Content class
 
var s:Sprite = new Sprite();
 
// onComplete event
 
 
// this gives an error saying TypeError: Error #1034: Type Coercion failed: cannot convert flash.display::Bitmap@33d3779 to flash.display.Sprite.
 
s = Object(ImageLoader.getImage());
 

Any idea on how to solve this problem

Thanks in advance

images are Bitmap class which is different from Sprite because Sprite also extends InteractiveObject, Bitmap doesn’t.
Instead casting Bitmap to Sprite use

var s:Sprite = new Sprite();
s.addChild(ImageLoader.getImage());

Hi yea I kind of sorted the problem out and just for others who are interested in this post what i did is insteading of assigning bitmap data to the sprite I have added that as a child of the sprite.

_imageSprite.addChild(ImageLoader.getInstance().getImage());

Ps I have made the loadedImage a displayObject cuz Bitmap is really a display object

Any further questions please do not hesitate to contact