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

}
4

1 回答 1

-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)
    }
 }
于 2012-12-02T15:28:58.117 回答