用自己的脑袋去做事情

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理
使用一个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);
  }
  
 }

}

posted on 2008-03-06 11:09  netlynx2000  阅读(388)  评论(0编辑  收藏  举报