home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Diversos / Jumper.swf / scripts / mx / core / MovieClipLoaderAsset.as < prev    next >
Encoding:
Text File  |  2008-09-05  |  3.0 KB  |  118 lines

  1. package mx.core
  2. {
  3.    import flash.display.Loader;
  4.    import flash.events.Event;
  5.    import flash.system.ApplicationDomain;
  6.    import flash.system.LoaderContext;
  7.    import flash.utils.ByteArray;
  8.    
  9.    use namespace mx_internal;
  10.    
  11.    public class MovieClipLoaderAsset extends MovieClipAsset implements IFlexAsset, IFlexDisplayObject
  12.    {
  13.       
  14.       mx_internal static const VERSION:String = "3.0.0.0";
  15.        
  16.       
  17.       protected var initialHeight:Number = 0;
  18.       
  19.       private var loader:Loader = null;
  20.       
  21.       private var initialized:Boolean = false;
  22.       
  23.       protected var initialWidth:Number = 0;
  24.       
  25.       private var requestedHeight:Number;
  26.       
  27.       private var requestedWidth:Number;
  28.       
  29.       public function MovieClipLoaderAsset()
  30.       {
  31.          super();
  32.          var loaderContext:LoaderContext = new LoaderContext();
  33.          loaderContext.applicationDomain = new ApplicationDomain(ApplicationDomain.currentDomain);
  34.          if("allowLoadBytesCodeExecution" in loaderContext)
  35.          {
  36.             loaderContext["allowLoadBytesCodeExecution"] = true;
  37.          }
  38.          loader = new Loader();
  39.          loader.contentLoaderInfo.addEventListener(Event.COMPLETE,completeHandler);
  40.          loader.loadBytes(movieClipData,loaderContext);
  41.          addChild(loader);
  42.       }
  43.       
  44.       override public function get width() : Number
  45.       {
  46.          if(!initialized)
  47.          {
  48.             return initialWidth;
  49.          }
  50.          return super.width;
  51.       }
  52.       
  53.       override public function set width(value:Number) : void
  54.       {
  55.          if(!initialized)
  56.          {
  57.             requestedWidth = value;
  58.          }
  59.          else
  60.          {
  61.             loader.width = value;
  62.          }
  63.       }
  64.       
  65.       override public function get measuredHeight() : Number
  66.       {
  67.          return initialHeight;
  68.       }
  69.       
  70.       private function completeHandler(event:Event) : void
  71.       {
  72.          initialized = true;
  73.          initialWidth = loader.width;
  74.          initialHeight = loader.height;
  75.          if(!isNaN(requestedWidth))
  76.          {
  77.             loader.width = requestedWidth;
  78.          }
  79.          if(!isNaN(requestedHeight))
  80.          {
  81.             loader.height = requestedHeight;
  82.          }
  83.          dispatchEvent(event);
  84.       }
  85.       
  86.       override public function set height(value:Number) : void
  87.       {
  88.          if(!initialized)
  89.          {
  90.             requestedHeight = value;
  91.          }
  92.          else
  93.          {
  94.             loader.height = value;
  95.          }
  96.       }
  97.       
  98.       override public function get measuredWidth() : Number
  99.       {
  100.          return initialWidth;
  101.       }
  102.       
  103.       override public function get height() : Number
  104.       {
  105.          if(!initialized)
  106.          {
  107.             return initialHeight;
  108.          }
  109.          return super.height;
  110.       }
  111.       
  112.       public function get movieClipData() : ByteArray
  113.       {
  114.          return null;
  115.       }
  116.    }
  117. }
  118.