csuo
csuo

Reputation: 820

Loader Complete event does not work with browser (AS3)

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.

Upvotes: 0

Views: 1666

Answers (3)

khailcs
khailcs

Reputation: 318

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;
}

Upvotes: 1

khailcs
khailcs

Reputation: 318

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);
}

Upvotes: 0

Ronnie
Ronnie

Reputation: 11198

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

Upvotes: 0

Related Questions