Loader Complete event does not work with browser (AS3)

北城余情 提交于 2019-12-12 05:07:44

问题


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.


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



回答2:


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




回答3:


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


来源:https://stackoverflow.com/questions/14735975/loader-complete-event-does-not-work-with-browser-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!