Log in

View Full Version : Centering Image inside of movieclip



crimsonsmeagol
02-25-2009, 05:19 PM
I am loading images into a scroll pane from an XML file and I need to center it inside the scroll pane if the image is smaller then the scroll pane. How can I do this?

This is the code I have but it says it cannot access a property or method of a null object reference.



private function onImageSelected(event:Event):void
{
var image:Image = event.target.selectedItem.data as Image;
var index:int = event.target.selectedIndex;
_thumbnails_tl.selectedIndex = index;
_title_lbl.text = image.name + "\n" + image.desc;
_imagePane_sp.source = image.file;

var desiredWidth = 800;

if(_imagePane_sp.content.width < desiredWidth) {
_imagePane_sp.content.x = (desiredWidth - _imagePane_sp.content.width)/2;
} else {
_imagePane_sp.content.x = 0;
}
}

Thank you in advance for all of your help.

Medyman
02-26-2009, 02:24 PM
Take a look at Lee Brimelow's Full Browser Flash tutorial on gotoandlearn.com. I think that'll help you develop your logic.

crimsonsmeagol
03-04-2009, 04:12 PM
Ok, I watched the video and the logic makes sense. My problem is accessing the x and y value of the image inside the scroll pane. This is the code I've tried


_imagePane_sp.content.x = _imagePane_sp.width /2;

However, in content.x the x value is not accessible.

I can't just center it to the stage because their is more content in the flash gallery then just the image and the image will not be completely centered in the flash player, just centered in the scroll pane.

Any suggestions?