Bill
Bill

Reputation: 19248

Greensock ImageLoader load image as bitmap not create movieclip

I have use greensock imageloader for sometimes (It's a great plug-in so easy to use and i love it), just wondering is there a way you can load bitmap which doesn't create a movieclip inside the container? I couldn't find this solution in the API http://www.greensock.com/as/docs/tween/com/greensock/loading/ImageLoader.html

does anyone have any experience?

Cheers Bill

Upvotes: 0

Views: 2706

Answers (1)

Neil
Neil

Reputation: 8111

According to the docs:

The ImageLoader's content refers to a ContentDisplay (Sprite) that is created immediately so that you can position/scale/rotate it or add ROLL_OVER/ROLL_OUT/CLICK listeners before (or while) the image loads. Use the ImageLoader's content property to get the ContentDisplay Sprite, or use the rawContent property to get the actual Bitmap. If a container is defined in the vars object, the ContentDisplay will immediately be added to that container).

So they are saying you don't have to supply a container in the vars object. If you just want to get the bitmap then it says you can use the rawContent property.

Try something like this:

//create an ImageLoader:
var loader:ImageLoader = new ImageLoader("your_image.jpg", {name:"image", 
x:0, y:0, width:200, height:200, onComplete:onImageLoad});

//begin loading
loader.load();

//see if we have a bitmap
function onImageLoad(event:LoaderEvent):void {
   trace(event.target.rawContent);
}

Although you say that you like this, loading a bitmap is trivial in AS3 without a library:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("your_image.png"));

function onComplete (event:Event):void
{
     // get your loaded bitmap
     var bmp:Bitmap = Bitmap(LoaderInfo(event.target).content);
}

Upvotes: 2

Related Questions