无论如何在使用URLLoader加载图片时不使用Loader显示加载的图片

时间:2012-12-02 03:15:15

标签: actionscript-3

public class NewClass  extends Sprite 
{

    public function NewClass() 
    {
        var req:URLRequest = new URLRequest();
        req.url = "http://www.nasa.gov/images/content/708545main_pia16453-43_full.jpg";
        req.method = URLRequestMethod.GET;
         var loader:URLLoader = new URLLoader();
        loader.load(req);
        loader.dataFormat = URLLoaderDataFormat.BINARY;
        loader.addEventListener(Event.COMPLETE, onImageLoaded);
    }

        //  Is there anyway to show the loaded picture without using Loader???
        private function onImageLoaded(e:Event):void {
                    var _ba:ByteArray = e.target.data as ByteArray;

                  /*                        var _l:Loader = new Loader;
                    _l.contentLoaderInfo.addEventListener (Event.COMPLETE, onBytesLoaded);
                    _l.loadBytes(_ba);
        e.target.removeEventListener (Event.COMPLETE , onImageLoaded);*/

        }

        private function onBytesLoaded(e:Event):void 
         {
                    var _bitmap:Bitmap = e.target.content as Bitmap;
                    trace(_bitmap.width, _bitmap.height );
                    addChild (_bitmap );
                    //
                    e.target.loader.contentLoaderInfo.removeEventListener (Event.COMPLETE, onBytesLoaded);
         }  

}

1 个答案:

答案 0 :(得分:-1)

我知道的唯一方法是在Flash中将图片拖到舞台上然后将其转换为MovieClip并选中“Export for ActionScript”框并命名该类(例如“image”)。之后你可以通过以下代码来完成。

public class NewClass extends Sprite
{
    private var picture:image=new image();

    public function NewClass
{ 
    picture.width=100; //example
    picture.height=100; //example
    addChild(picture)
    }
 }