Question

I'm developing an ActionScript 3.0 app for Blackberry Playbook.

I have a Loader with a fixed size of 240x240px. The images that can be loaded inside are smaller or bigger than 240x240px, and also they aren't squared.

I use this code to resize that images:

private function onLoadedEvent(event:Event):void
{
    var targetLoader:Loader = Loader(event.target.loader);
    var factor:Number;
    if (targetLoader.content.height > targetLoader.content.width) {
        factor = 240/targetLoader.content.height;
    } 
    else
    {
        factor = 240/targetLoader.content.width;
    }
    targetLoader.content.height = targetLoader.content.height * factor;
    targetLoader.content.width = targetLoader.content.width * factor;
}

How can I do to set that images centered vertically inside that Loader?

Was it helpful?

Solution

I think this should do (putting it after the resize) unless I misunderstood your question:

targetLoader.content.y = (240 - targetLoader.content.height) / 2
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top