Well that is one day to do it, but this should work better: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"> <mx:Image id="myimage" maintainAspectRatio="true" source="@Embed(source='images.jpg')" scaleContent="true" width="100%" height="100%" horizontalAlign="middle" verticalAlign="middle" /> </mx:Application>
So the issue with the code is more an understanding of scaling: My expectation from this code is that the image should fit the screen, > maintain the aspect ratio of the image and finally be both centered > horizontally and vertically! > Techinically the Image above 'fits' the screen, that is its width and height is set to 100% of the application. Since it fills the application completely, setting verticalCenter and horizontalCenter have no effect. You would have to set a width and height of the Image's *content* to center, not the image itself. An important but subtle distinction. The Image control contains an image, but will have empty space inside it also if maintainAspectRatio is true. The alignment of the contents within the Image is controlled by the horizontalAlign and verticalAlign styles. Peace C On Mon, Nov 30, 2009 at 10:03 PM, ganaraj p r <[email protected]> wrote: > > > Hi, > > Thanks. Yes. But that is a workaround right? > > I wanted to know if this was a bug with flex! Or if there was an mxml way > of doing it. > > > On Mon, Nov 30, 2009 at 5:42 PM, Manoj Kumar <[email protected]>wrote: > >> >> >> try this mt- >> >> private function onAppComplete():void >> { >> stage.addEventListener(Event.RESIZE,onResize); >> _spr.x = (stage.stageWidth - _spr.width)/2; >> _spr.y = (stage.stageHeight - _spr.height)/2; >> _ui.width = stage.stageWidth; >> _ui.height = stage.stageHeight; >> } >> private function onResize(evt:Event):void >> { >> _spr.x = (stage.stageWidth - _spr.width)/2; >> _spr.y = (stage.stageHeight - _spr.height)/2; >> _ui.width = stage.stageWidth; >> _ui.height = stage.stageHeight; >> } >> >> >> >> --- On *Mon, 11/30/09, ganaraj p r <[email protected]>* wrote: >> >> >> From: ganaraj p r <[email protected]> >> Subject: [flexcoders] Centering a Scaled Image ( Bug ? ) [1 Attachment] >> To: [email protected], [email protected] >> Date: Monday, November 30, 2009, 4:08 PM >> >> >> >> >> I was wondering if this was a bug with flex or if I was doing something >> totally wrong. >> >> The amount of code in this is extremely low, so , I was guessing that >> there was nothing wrong from my part. >> >> <?xml version="1.0" encoding="utf-8"?> >> <mx:Application xmlns:mx="http://www.adobe. com/2006/ >> mxml<http://www.adobe.com/2006/mxml>" >> layout="absolute"> >> <mx:Image id="myimage" maintainAspectRatio ="true" >> horizontalCenter="0" verticalCenter="0" >> source="@Embed(source='images.jpg')" >> scaleContent="true" width="100%" height="100%"/> >> </mx:Application> >> >> >> This is all the code there is in this application ( I am attaching the >> app, for your reference ) . >> My expectation from this code is that the image should fit the screen, >> maintain the aspect ratio of the image and finally be both centered >> horizontally and vertically! >> >> >> Can someone help me out in this ? >> >> -- >> Regards, >> Ganaraj P R >> >> >> > > > -- > Regards, > Ganaraj P R > >

