BTA Flexing

My passion RIAs…………..Shardul Singh Bartwal

Using Image Inside the Sprite in Flex

Posted by Shardul Singh Bartwal on September 18, 2009

Using Image Inside the Sprite in Flex

If we want to add any Image inside the Sprite class in flex,then It is not possible to add image inside the sprite. But if your requirement is as such in that case you can achieve this by adding the Loader inside the sprite. Below is the code for the same.


<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="" 
layout="absolute" creationComplete="createSpriteWithBitmap()">
	import mx.controls.Image;
	private function createSpriteWithBitmap():void
	var sp : SpriteWithBitmap = new SpriteWithBitmap();
	can.rawChildren.addChild( sp );
	<mx:Canvas id="can" x="200" y="200"/>


import flash.display.Loader;
import flash.display.Sprite;

import mx.controls.Alert;

public class SpriteWithBitmap extends Sprite
	//Pass the source path or url here. 
	private var url:String = "";

	public function SpriteWithBitmap() 
	private function loadImg():void 
		var loader:Loader = new Loader();
		loader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadFailure);
		var request:URLRequest = new URLRequest(url);

	private function loadFailure(event:IOErrorEvent):void
	{"Can't load :" + url);


Enjoy Flexing………….


4 Responses to “Using Image Inside the Sprite in Flex”

  1. […] I linked to above.  The Key class came from and the SpriteWithBitmap class came from The files are hosted on this blog in-case either of those websites goes off-line, or changes their […]

  2. pushkar said

    pls give me another code. it is not working. faltu hai..

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: