0

Im trying to load an image in a movie clip and change its size as follow:

    var loader:Loader = new Loader();

    public function setProfilePicture(url:String){
        loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplte);
        loader.load(new URLRequest(url));
        addChild(loader);
    }


    protected function onComplte(event:Event):void
    {
        EventDispatcher(event.target).removeEventListener(event.type, arguments.callee);
        var image:DisplayObject = (event.target as LoaderInfo).content;
        image.width = 132;
        image.height = 132;

    }

The code above works fine when I execute it with adobe flash CS5, but when I try to open it with a browser (e.g. Chrome), the size of images does not change to 132x132. I tried to put addChild(loader) in the onComplete function, but in this time when I open it with a browser, the image won't be even loaded, while executing with adobe flash CS5 remains as before.

My suggestion is that when we open it by browser, the function onComplete does not work, but WHY??? Any idea will be appreciated.

BadFeelingAboutThis
  • 14,445
  • 2
  • 33
  • 40
csuo
  • 820
  • 3
  • 16
  • 31

3 Answers3

1

Try this hack:

protected function onComplte( event:Event ):void {
    EventDispatcher( event.target ).removeEventListener( event.type, arguments.callee );

    var loaderInfo:LoaderInfo = LoaderInfo( event.target );
    loaderInfo.loader.scaleX = 132 / loaderInfo.width;
    loaderInfo.loader.scaleY = 132 / loaderInfo.height;
}
khailcs
  • 328
  • 1
  • 9
0

check this link: actionscript3 (flash) don't load images form user file in chrome

Verify that it works in a different browser other than chrome. This is most likely the pepper flash problem in chrome

Community
  • 1
  • 1
Ronnie
  • 11,138
  • 21
  • 78
  • 140
0

I played with your onComplte function and somehow the content property of LoaderInfo is not accessible from in there. If all else fail, the size of the image can still be controlled from within setProfilePicture by scaling the Loader:

public function setProfilePicture(url:String){
    loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplte);
    loader.load(new URLRequest(url));
    loader.scaleX = 10; ////
    loader.scaleY = 10; ////
    addChild(loader);
}
khailcs
  • 328
  • 1
  • 9
  • Thanks for your answer, the problem of your solution is that the size of the image can be different, so by using the scaleX property the final size is not guaranty to be what we want. – csuo Feb 07 '13 at 11:09