Results 1 to 3 of 3

Thread: Centering Image inside of movieclip

  1. #1
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default Centering Image inside of movieclip

    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.

    Code:
     
    		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.
    Last edited by crimsonsmeagol; 02-25-2009 at 06:01 PM.

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    Take a look at Lee Brimelow's Full Browser Flash tutorial on gotoandlearn.com. I think that'll help you develop your logic.

  3. #3
    Join Date
    Feb 2008
    Posts
    33
    Thanks
    4
    Thanked 1 Time in 1 Post

    Default

    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

    Code:
     _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?

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •