装载机完整的事件不会与浏览器的工作(AS3)装载机、浏览器、完整、事件

2023-09-09 21:53:46 作者:给你︶白头偕老的爱情ㄣ

我试着去加载图像中的影片剪辑并更改其尺寸如下:

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;

    }

在code以上正常工作时,我在Adobe Flash CS5执行它,但是当我尝试用一​​个浏览器(如浏览器)打开它,图像的大小不会更改为132x132。我试图把的addChild(装载机)中的onComplete的功能,但在这个时候,我用浏览器打开它时,图像不会连装,而在Adobe Flash CS5执行像以前一样保持。

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.

我的建议是,当我们通过浏览器打开,该函数的onComplete不工作,但为什么??? 任何想法将AP preciated。

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

推荐答案

试试这个黑客:

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