OK, I'm now confused.  If you want an image to fill a canvas then you
don't really need to center it (unless there's going to be distortion
from aspect ratio changing).  And, if you fill the Canvas, I'd think
you'd just use the backgroundImage instead.
 
Can you provide more details on the scenario?
-Alex

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of herklano
Sent: Monday, April 02, 2007 7:51 AM
To: [email protected]
Subject: [flexcoders] Re: is there a simple way to center a loaded
image?



hi,

i tried that aprouch but the problem is that i want to scale the image
to the canvas boundaries, so i really think the only way to do it is
through AS.

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "B. Korsmit" <[EMAIL PROTECTED]> wrote:
>
> Hi Herklano,
> 
> You probably want to use the horizontalAlign and verticalAlign
styles to 
> do this?
> 
> <mx:Image
> id="SMCDadosImg"
> horizontalCenter="0"
> verticalCenter="0"
> horizontalAlign="center"
> verticalAlign="middle"
> />
> 
> That's what I often use...
> 
> 
> 
> herklano wrote:
> >
> > hi,
> >
> > i'm kinda noob at coding in general, but i'm trying to work my way
to
> > get a image that is loaded in a Canvas to center to it after it has
> > been loaded to it.
> >
> > i'm trying this but it doesn't work:
> >
> > <mx:Canvas
> > x="10" y="10" width="190" borderStyle="none"
> > backgroundColor="#d0d0d0" height="190">
> > <mx:Image id="SMCDadosImg"
> > complete="changeSMCDadosImg(event);" horizontalCenter="0"
> > verticalCenter="0"/>
> > </mx:Canvas>
> >
> > private function changeSMCDadosImg(event:Event):void
> > {
> > var pW_SMCDadosImg:Number;
> > var pH_SMCDadosImg:Number;
> >
> > pW_SMCDadosImg = event.target.width;
> > pH_SMCDadosImg = event.target.height;
> >
> > trace("W = "+ pW_SMCDadosImg);
> > trace("H = "+ pH_SMCDadosImg);
> >
> > if (pW_SMCDadosImg > pH_SMCDadosImg)
> > {
> > SMCDadosImg.height = 190;
> > SMCDadosImg.width = pW_SMCDadosImg/(190*pH_SMCDadosImg);
> > SMCDadosImg.x = 190/2 - SMCDadosImg.width/2;
> > }
> > else if (pW_SMCDadosImg < pH_SMCDadosImg)
> > {
> > SMCDadosImg.width = 190;
> > SMCDadosImg.height = pH_SMCDadosImg/(190*pW_SMCDadosImg);
> > SMCDadosImg.y = 190/2 - SMCDadosImg.height/2;
> > }
> > else if (pW_SMCDadosImg == pH_SMCDadosImg)
> > {
> > SMCDadosImg.height = 190;
> > SMCDadosImg.width = 190;
> > }
> > }
> >
> >
>



 

Reply via email to