使用一个Loaderload资源时报错误
Title
所提供的
DisplayObject 必须为
调用方的子级
的解决方案
Title
package com.asdia.comptest
{
import flash.display.Bitmap;
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
import flash.system.System;
public class DisplayTesting extends Sprite
{
public var text:String ;
private static var _loader:Loader= null;
public function DisplayTesting()
{
}
public function LoadImg():void{
//_loader=new Loader();
_loader=getLoaderIntance();
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,showImg)
if(_loader.content!=null){
_loader.removeEventListener(Event.COMPLETE,showImg);
_loader=null;
_loader=getLoaderIntance();
}
_loader.contentLoaderInfo.addEventListener(Event.COMPLETE,showImg)
_loader.load(new URLRequest("http://images.sohu.com/uiue/sohu_logo/beijing2008/2008sohu.gif"));
}
static public function getLoaderIntance():Loader{
if(_loader==null){
_loader=new Loader();
return _loader;
}else{
return _loader;
}
}
private function showImg(event:Event):void{
var image:Bitmap=_loader.contentLoaderInfo.content as Bitmap;
this.addChild(image);
trace(System.totalMemory);
}
}
}