Actionscript 3 在使用URLLoader加载图片时,是否仍然可以在不使用Loader的情况下显示加载的图片
我知道的唯一方法是在Flash中拖动舞台上的图片,然后将其转换为MovieClip,选中“Export for ActionScript”框并命名该类(例如“image”)。之后,您可以按照下面的代码进行操作Actionscript 3 在使用URLLoader加载图片时,是否仍然可以在不使用Loader的情况下显示加载的图片,actionscript-3,Actionscript 3,我知道的唯一方法是在Flash中拖动舞台上的图片,然后将其转换为MovieClip,选中“Export for ActionScript”框并命名该类(例如“image”)。之后,您可以按照下面的代码进行操作 public class NewClass extends Sprite { public function NewClass() { var req:URLRequest = new URLRequest(); req.url =
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);
}
}
public class NewClass extends Sprite
{
private var picture:image=new image();
public function NewClass
{
picture.width=100; //example
picture.height=100; //example
addChild(picture)
}
}