PDA

View Full Version : Load images as Sprite Problem


bbarney261
10-19-2008, 12:58 AM
I'm loading some images into an image gallery. I'm having trouble figuring out how to put each image into a Sprite so I can access the mouse events. When a users clicks on a image I would like to load an external page. Here is the code that I have:

function spaceImages():void{
mcContainer.x = 10;
mcContainer.y = 79;
for(var i:int = 0; i < images.length;i++){
images[i].x = images[i].width * i + padding;
mcContainer.addChild(images[i]);
}
}

Does anyone know a way that I could add the images to a sprite and then add the sprite to mcContainer?

Any help you be greatly appreciated.

Thanks in advance!

matbury
10-19-2008, 01:57 PM
Hi bbarney261,

We'd need to see how you're loading your images to help you. Are you using Loader? If so, Loader has all the same DisplayObject properties as Sprite so it's effectively already a Sprite. You can assign it to a varaible to make it easier to handle like this:

var obj:DisplayObject;

function loadComplete(event:Event):void {
loader.contentLoaderInfo.removeEventListener(Event .INIT, loadComplete);
obj = loader.contentLoaderInfo.content;
}

Hope this helps!

Matt :)

bbarney261
10-19-2008, 10:06 PM
Matt,

Thanks for your help with this, it worked perfect.

Brett

matbury
10-20-2008, 02:16 AM
You're welcome! :)