# Converting bitmapdisplay object to sprite (Please help)

**URL:** https://forum.kirupa.com/t/converting-bitmapdisplay-object-to-sprite-please-help/260680
**Category:** flash
**Created:** [May 18, 2008, 7:31pm UTC](https://forum.kirupa.com/t/converting-bitmapdisplay-object-to-sprite-please-help/260680 "2008-05-18T19:31:15Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![adnan794](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@adnan794](https://forum.kirupa.com/u/adnan794)
#### Post date: [May 18, 2008, 7:31pm UTC](https://forum.kirupa.com/t/converting-bitmapdisplay-object-to-sprite-please-help/260680/1 "2008-05-18T19:31:15Z")

</div>

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

```auto

//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

```auto

//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

---

<div class="post-metadata">

### Author: ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)
#### Post date: [May 18, 2008, 7:45pm UTC](https://forum.kirupa.com/t/converting-bitmapdisplay-object-to-sprite-please-help/260680/2 "2008-05-18T19:45:42Z")

</div>

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

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

```

---

<div class="post-metadata">

### Author: ![adnan794](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@adnan794](https://forum.kirupa.com/u/adnan794)
#### Post date: [May 18, 2008, 7:50pm UTC](https://forum.kirupa.com/t/converting-bitmapdisplay-object-to-sprite-please-help/260680/3 "2008-05-18T19:50:37Z")

</div>

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());

---

<div class="post-metadata">

### Author: ![adnan794](https://avatars.discourse-cdn.com/v4/letter/a/8edcca/32.png) [@adnan794](https://forum.kirupa.com/u/adnan794)
#### Post date: [May 18, 2008, 7:51pm UTC](https://forum.kirupa.com/t/converting-bitmapdisplay-object-to-sprite-please-help/260680/4 "2008-05-18T19:51:36Z")

</div>

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

Any further questions please do not hesitate to contact
