如何一个Loader加载多个资源

本文介绍了一个使用Flash中的Loader类加载图片资源的方法,并详细解释了如何确保所加载的资源能正确成为调用者的子对象,避免了因资源未成为子对象而导致的显示问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

使用一个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);
  }
  
 }

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值