ActionScript 3 装载机类

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ActionScript 3 装载机类相关的知识,希望对你有一定的参考价值。

/*

Usage: 

import com.zguillez.display.Contenedor;

var cont:Contenedor = new Contenedor();
cont.asset = "pelicula.swf"


cont.addEventListener(Contenedor.CARGADO, listo);
function listo(e:Event):void
{
   trace("carga lista")
}
cont.asset = "pelicula2.swf"


*/

package com.zguillez.display
{
   import flash.display.Sprite;
   import flash.display.Loader;
   import flash.net.URLRequest;
   import flash.events.Event;
   import flash.events.EventDispatcher;
   //-----------------------------------------
   public class Contenedor extends Sprite
   {
      public static  var CARGADO:String = "cargado";
      private var _clip:Sprite = new Sprite();
      private var _cargado:Boolean = false;
      private var _content:Sprite;
      private var _urlAsset:String;
      //-----------------------------------------
      public function Contenedor(asset:String=null)
      {
         _urlAsset = asset;
         if (_urlAsset != null) {
            iniLoad();
         }
      }
      //-----------------------------------------
      private function iniLoad(asset:String=null):void
      {
         var loader:Loader = new Loader();
         var request:URLRequest = new URLRequest(_urlAsset);
         loader.load(request);
         var dispatcher:EventDispatcher = loader.contentLoaderInfo;
         dispatcher.addEventListener(Event.INIT, registraContenido);
         addChild(loader);
      }
      //-----------------------------------------
      public function set asset(a:String):void
      {
         if (_urlAsset != null) {
            removeChild(_clip);
         }
         _urlAsset = a;
         iniLoad();
      }
      //-----------------------------------------
      public function get clip():Sprite
      {
         return _clip;
      }
      public function get cargado():Boolean
      {
         return _cargado;
      }
      //-----------------------------------------
      public function registraContenido(e:Event):void
      {
         _cargado = true;
         _clip = e.target.content;
         dispatchEvent(new Event(Contenedor.CARGADO));
      }
      //-----------------------------------------
   }
}

以上是关于ActionScript 3 装载机类的主要内容,如果未能解决你的问题,请参考以下文章

ActionScript 3 flashvars装载机

ActionScript 3 装载机政策标志

ActionScript 3 AS3装载机

ActionScript 3 装载机

ActionScript 3 最顶级的父装载机信息

ActionScript 3 AS3装载机垃圾收集