I'm loading a large image into a canvas. When the image loads, I want
to center the image inside the view port. Here is how I have the image
defined:

        <mx:Canvas id="viewport" width="100%" height="100%"
vScrollPolicy="off" hScrollPolicy="off">
                <mx:Image id="mapImage" source="{mapPath}"
                                        mouseDown="handleMouseDown()"
                                        mouseUpSomewhere="handleMouseUp()"
                                        mouseMoveSomewhere="handleMouseMove()" 
/>
        </mx:Canvas>

I've tried a code to center items like so:

                function center() {
                        var viewPortWidth:Number = viewport.width;
                        var viewPortHeight:Number = viewport.height;
                        var thisWidth = this.mapImage.width;
                        var thisHeight = this.mapImage.height;
                        
                        var newX = Math.round((viewPortWidth - thisWidth) / 2);
                        var newY = Math.round((viewPortHeight - thisHeight) / 
2);
                        
                        this.mapImage.x = -1 * newX;
                        this.mapImage.y = -1 * newY;
                        
                        Echo.debug("new coord "+newX +","+ newY+" the width was 
"+thisWidth);
                }

However, I noticed that width was 0, so I got unexpected results. Do I
need to wait for the image to finish loading? If so - how/when  would
I run center?

--
=======================================================================
Raymond Camden, Director of Development for Mindseye, Inc (www.mindseye.com)

Member of Team Macromedia (http://www.macromedia.com/go/teammacromedia)

Email    : [EMAIL PROTECTED]
Blog     : ray.camdenfamily.com
Yahoo IM : cfjedimaster

"My ally is the Force, and a powerful ally it is." - Yoda


------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/nhFolB/TM
--------------------------------------------------------------------~-> 

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to