home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / HexiomConnect.swf / scripts / MochiAd.as < prev    next >
Text File  |  2008-08-29  |  31KB  |  926 lines

  1. package
  2. {
  3.    import flash.display.DisplayObjectContainer;
  4.    import flash.display.Loader;
  5.    import flash.display.MovieClip;
  6.    import flash.events.Event;
  7.    import flash.net.LocalConnection;
  8.    import flash.net.URLRequest;
  9.    import flash.net.URLRequestMethod;
  10.    import flash.net.URLVariables;
  11.    import flash.system.Security;
  12.    import flash.utils.getTimer;
  13.    import flash.utils.setTimeout;
  14.    
  15.    public class MochiAd
  16.    {
  17.        
  18.       
  19.       public function MochiAd()
  20.       {
  21.          super();
  22.       }
  23.       
  24.       public static function getVersion() : String
  25.       {
  26.          return "2.5";
  27.       }
  28.       
  29.       public static function showClickAwayAd(param1:Object) : void
  30.       {
  31.          var clip:Object = null;
  32.          var mc:MovieClip = null;
  33.          var chk:MovieClip = null;
  34.          var options:Object = param1;
  35.          var DEFAULTS:Object = {
  36.             "ad_timeout":2000,
  37.             "regpt":"o",
  38.             "method":"showClickAwayAd",
  39.             "res":"300x250",
  40.             "no_bg":true,
  41.             "ad_started":function():void
  42.             {
  43.             },
  44.             "ad_finished":function():void
  45.             {
  46.             },
  47.             "ad_loaded":function(param1:Number, param2:Number):void
  48.             {
  49.             },
  50.             "ad_failed":function():void
  51.             {
  52.                trace("[MochiAd] Couldn\'t load an ad, make sure your game\'s local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
  53.             },
  54.             "ad_skipped":function():void
  55.             {
  56.             }
  57.          };
  58.          options = MochiAd._parseOptions(options,DEFAULTS);
  59.          clip = options.clip;
  60.          var ad_timeout:Number = options.ad_timeout;
  61.          delete options.ad_timeout;
  62.          if(!MochiAd.load(options))
  63.          {
  64.             options.ad_failed();
  65.             options.ad_finished();
  66.             return;
  67.          }
  68.          options.ad_started();
  69.          mc = clip._mochiad;
  70.          mc["onUnload"] = function():void
  71.          {
  72.             MochiAd._cleanup(mc);
  73.             options.ad_finished();
  74.          };
  75.          var wh:Array = MochiAd._getRes(options,clip);
  76.          var w:Number = wh[0];
  77.          var h:Number = wh[1];
  78.          mc.x = w * 0.5;
  79.          mc.y = h * 0.5;
  80.          chk = createEmptyMovieClip(mc,"_mochiad_wait",3);
  81.          chk.ad_timeout = ad_timeout;
  82.          chk.started = getTimer();
  83.          chk.showing = false;
  84.          mc.unloadAd = function():void
  85.          {
  86.             MochiAd.unload(clip);
  87.          };
  88.          mc.adLoaded = options.ad_loaded;
  89.          mc.adSkipped = options.ad_skipped;
  90.          mc.rpc = function(param1:Number, param2:Object):void
  91.          {
  92.             MochiAd.rpc(clip,param1,param2);
  93.          };
  94.          var sendHostProgress:Boolean = false;
  95.          mc.regContLC = function(param1:String):void
  96.          {
  97.             mc._containerLCName = param1;
  98.          };
  99.          chk["onEnterFrame"] = function():void
  100.          {
  101.             var _loc4_:Number = NaN;
  102.             if(!this.parent)
  103.             {
  104.                delete this.onEnterFrame;
  105.                return;
  106.             }
  107.             var _loc1_:Object = this.parent._mochiad_ctr;
  108.             var _loc2_:Number = getTimer() - this.started;
  109.             var _loc3_:Boolean = false;
  110.             if(!chk.showing)
  111.             {
  112.                if((_loc4_ = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal) > 0)
  113.                {
  114.                   chk.showing = true;
  115.                   _loc3_ = true;
  116.                   chk.started = getTimer();
  117.                }
  118.                else if(_loc2_ > chk.ad_timeout)
  119.                {
  120.                   options.ad_failed();
  121.                   _loc3_ = true;
  122.                }
  123.             }
  124.             if(this.root == null)
  125.             {
  126.                _loc3_ = true;
  127.             }
  128.             if(_loc3_)
  129.             {
  130.                delete this.onEnterFrame;
  131.             }
  132.          };
  133.          doOnEnterFrame(chk);
  134.       }
  135.       
  136.       public static function _isNetworkAvailable() : Boolean
  137.       {
  138.          return Security.sandboxType != "localWithFile";
  139.       }
  140.       
  141.       public static function _allowDomains(param1:String) : String
  142.       {
  143.          var _loc2_:String = param1.split("/")[2].split(":")[0];
  144.          Security.allowDomain("*");
  145.          Security.allowDomain(_loc2_);
  146.          Security.allowInsecureDomain("*");
  147.          Security.allowInsecureDomain(_loc2_);
  148.          return _loc2_;
  149.       }
  150.       
  151.       public static function unload(param1:Object) : Boolean
  152.       {
  153.          if(param1.clip && param1.clip._mochiad)
  154.          {
  155.             param1 = param1.clip;
  156.          }
  157.          if(param1.origFrameRate != undefined)
  158.          {
  159.             param1.stage.frameRate = param1.origFrameRate;
  160.          }
  161.          if(!param1._mochiad)
  162.          {
  163.             return false;
  164.          }
  165.          if(param1._mochiad._containerLCName != undefined)
  166.          {
  167.             param1._mochiad.lc.send(param1._mochiad._containerLCName,"notify",{"id":"unload"});
  168.          }
  169.          if(param1._mochiad.onUnload)
  170.          {
  171.             param1._mochiad.onUnload();
  172.          }
  173.          delete param1._mochiad_loaded;
  174.          delete param1._mochiad;
  175.          return true;
  176.       }
  177.       
  178.       public static function showInterLevelAd(param1:Object) : void
  179.       {
  180.          var clip:Object = null;
  181.          var mc:MovieClip = null;
  182.          var chk:MovieClip = null;
  183.          var options:Object = param1;
  184.          var DEFAULTS:Object = {
  185.             "ad_timeout":2000,
  186.             "fadeout_time":250,
  187.             "regpt":"o",
  188.             "method":"showTimedAd",
  189.             "ad_started":function():void
  190.             {
  191.                if(this.clip is MovieClip)
  192.                {
  193.                   this.clip.stop();
  194.                   return;
  195.                }
  196.                throw new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip.  If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.");
  197.             },
  198.             "ad_finished":function():void
  199.             {
  200.                if(this.clip is MovieClip)
  201.                {
  202.                   this.clip.play();
  203.                   return;
  204.                }
  205.                throw new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip.  If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.");
  206.             },
  207.             "ad_loaded":function(param1:Number, param2:Number):void
  208.             {
  209.             },
  210.             "ad_failed":function():void
  211.             {
  212.                trace("[MochiAd] Couldn\'t load an ad, make sure your game\'s local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
  213.             },
  214.             "ad_skipped":function():void
  215.             {
  216.             }
  217.          };
  218.          options = MochiAd._parseOptions(options,DEFAULTS);
  219.          clip = options.clip;
  220.          var ad_msec:Number = 11000;
  221.          var ad_timeout:Number = options.ad_timeout;
  222.          delete options.ad_timeout;
  223.          var fadeout_time:Number = options.fadeout_time;
  224.          delete options.fadeout_time;
  225.          if(!MochiAd.load(options))
  226.          {
  227.             options.ad_failed();
  228.             options.ad_finished();
  229.             return;
  230.          }
  231.          options.ad_started();
  232.          mc = clip._mochiad;
  233.          mc["onUnload"] = function():void
  234.          {
  235.             MochiAd._cleanup(mc);
  236.             options.ad_finished();
  237.          };
  238.          var wh:Array = MochiAd._getRes(options,clip);
  239.          var w:Number = wh[0];
  240.          var h:Number = wh[1];
  241.          mc.x = w * 0.5;
  242.          mc.y = h * 0.5;
  243.          chk = createEmptyMovieClip(mc,"_mochiad_wait",3);
  244.          chk.ad_msec = ad_msec;
  245.          chk.ad_timeout = ad_timeout;
  246.          chk.started = getTimer();
  247.          chk.showing = false;
  248.          chk.fadeout_time = fadeout_time;
  249.          chk.fadeFunction = function():void
  250.          {
  251.             if(!this.parent)
  252.             {
  253.                delete this.onEnterFrame;
  254.                delete this.fadeFunction;
  255.                return;
  256.             }
  257.             var _loc1_:Number = 100 * (1 - (getTimer() - this.fadeout_start) / this.fadeout_time);
  258.             if(_loc1_ > 0)
  259.             {
  260.                this.parent.alpha = _loc1_ * 0.01;
  261.             }
  262.             else
  263.             {
  264.                MochiAd.unload(clip);
  265.                delete this["onEnterFrame"];
  266.             }
  267.          };
  268.          mc.unloadAd = function():void
  269.          {
  270.             MochiAd.unload(clip);
  271.          };
  272.          mc.adLoaded = options.ad_loaded;
  273.          mc.adSkipped = options.ad_skipped;
  274.          mc.adjustProgress = function(param1:Number):void
  275.          {
  276.             var _loc2_:Object = mc._mochiad_wait;
  277.             _loc2_.server_control = true;
  278.             _loc2_.showing = true;
  279.             _loc2_.started = getTimer();
  280.             _loc2_.ad_msec = param1 - 250;
  281.          };
  282.          mc.rpc = function(param1:Number, param2:Object):void
  283.          {
  284.             MochiAd.rpc(clip,param1,param2);
  285.          };
  286.          chk["onEnterFrame"] = function():void
  287.          {
  288.             var _loc4_:Number = NaN;
  289.             if(!this.parent)
  290.             {
  291.                delete this.onEnterFrame;
  292.                delete this.fadeFunction;
  293.                return;
  294.             }
  295.             var _loc1_:Object = this.parent._mochiad_ctr;
  296.             var _loc2_:Number = getTimer() - this.started;
  297.             var _loc3_:Boolean = false;
  298.             if(!chk.showing)
  299.             {
  300.                if((_loc4_ = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal) > 0)
  301.                {
  302.                   chk.showing = true;
  303.                   chk.started = getTimer();
  304.                   MochiAd.adShowing(clip);
  305.                }
  306.                else if(_loc2_ > chk.ad_timeout)
  307.                {
  308.                   options.ad_failed();
  309.                   _loc3_ = true;
  310.                }
  311.             }
  312.             if(_loc2_ > chk.ad_msec)
  313.             {
  314.                _loc3_ = true;
  315.             }
  316.             if(_loc3_)
  317.             {
  318.                if(this.server_control)
  319.                {
  320.                   delete this.onEnterFrame;
  321.                }
  322.                else
  323.                {
  324.                   this.fadeout_start = getTimer();
  325.                   this.onEnterFrame = this.fadeFunction;
  326.                }
  327.             }
  328.          };
  329.          doOnEnterFrame(chk);
  330.       }
  331.       
  332.       public static function _parseOptions(param1:Object, param2:Object) : Object
  333.       {
  334.          var _loc4_:* = null;
  335.          var _loc5_:Array = null;
  336.          var _loc6_:Number = NaN;
  337.          var _loc7_:Array = null;
  338.          var _loc3_:Object = {};
  339.          for(_loc4_ in param2)
  340.          {
  341.             _loc3_[_loc4_] = param2[_loc4_];
  342.          }
  343.          if(param1)
  344.          {
  345.             for(_loc4_ in param1)
  346.             {
  347.                _loc3_[_loc4_] = param1[_loc4_];
  348.             }
  349.          }
  350.          if(_loc3_.clip == undefined)
  351.          {
  352.             throw new Error("MochiAd is missing the \'clip\' parameter.  This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite.");
  353.          }
  354.          param1 = _loc3_.clip.loaderInfo.parameters.mochiad_options;
  355.          if(param1)
  356.          {
  357.             _loc5_ = param1.split("&");
  358.             _loc6_ = 0;
  359.             while(_loc6_ < _loc5_.length)
  360.             {
  361.                _loc7_ = _loc5_[_loc6_].split("=");
  362.                _loc3_[unescape(_loc7_[0])] = unescape(_loc7_[1]);
  363.                _loc6_++;
  364.             }
  365.          }
  366.          if(_loc3_.id == "test")
  367.          {
  368.             trace("[MochiAd] WARNING: Using the MochiAds test identifier, make sure to use the code from your dashboard, not this example!");
  369.          }
  370.          return _loc3_;
  371.       }
  372.       
  373.       public static function _cleanup(param1:Object) : void
  374.       {
  375.          var k:String = null;
  376.          var lc:LocalConnection = null;
  377.          var f:Function = null;
  378.          var mc:Object = param1;
  379.          if("lc" in mc)
  380.          {
  381.             lc = mc.lc;
  382.             f = function():void
  383.             {
  384.                try
  385.                {
  386.                   lc.client = null;
  387.                   lc.close();
  388.                }
  389.                catch(e:Error)
  390.                {
  391.                }
  392.             };
  393.             setTimeout(f,0);
  394.          }
  395.          var idx:Number = DisplayObjectContainer(mc).numChildren;
  396.          while(idx > 0)
  397.          {
  398.             idx--;
  399.             DisplayObjectContainer(mc).removeChildAt(idx);
  400.          }
  401.          for(k in mc)
  402.          {
  403.             delete mc[k];
  404.          }
  405.       }
  406.       
  407.       public static function load(param1:Object) : MovieClip
  408.       {
  409.          var clip:Object = null;
  410.          var k:String = null;
  411.          var server:String = null;
  412.          var hostname:String = null;
  413.          var lc:LocalConnection = null;
  414.          var name:String = null;
  415.          var loader:Loader = null;
  416.          var g:Function = null;
  417.          var req:URLRequest = null;
  418.          var v:Object = null;
  419.          var options:Object = param1;
  420.          var DEFAULTS:Object = {
  421.             "server":"http://x.mochiads.com/srv/1/",
  422.             "method":"load",
  423.             "depth":10333,
  424.             "id":"_UNKNOWN_"
  425.          };
  426.          options = MochiAd._parseOptions(options,DEFAULTS);
  427.          options.swfv = 9;
  428.          options.mav = MochiAd.getVersion();
  429.          clip = options.clip;
  430.          if(!MochiAd._isNetworkAvailable())
  431.          {
  432.             return null;
  433.          }
  434.          try
  435.          {
  436.             if(clip._mochiad_loaded)
  437.             {
  438.                return null;
  439.             }
  440.          }
  441.          catch(e:Error)
  442.          {
  443.             throw new Error("MochiAd requires a clip that is an instance of a dynamic class.  If your class extends Sprite or MovieClip, you must make it dynamic.");
  444.          }
  445.          var depth:Number = options.depth;
  446.          delete options.depth;
  447.          var mc:MovieClip = createEmptyMovieClip(clip,"_mochiad",depth);
  448.          var wh:Array = MochiAd._getRes(options,clip);
  449.          options.res = wh[0] + "x" + wh[1];
  450.          options.server += options.id;
  451.          delete options.id;
  452.          clip._mochiad_loaded = true;
  453.          if(clip.loaderInfo.loaderURL.indexOf("http") == 0)
  454.          {
  455.             options.as3_swf = clip.loaderInfo.loaderURL;
  456.          }
  457.          var lv:URLVariables = new URLVariables();
  458.          for(k in options)
  459.          {
  460.             v = options[k];
  461.             if(!(v is Function))
  462.             {
  463.                lv[k] = v;
  464.             }
  465.          }
  466.          server = lv.server;
  467.          delete lv.server;
  468.          hostname = _allowDomains(server);
  469.          lc = new LocalConnection();
  470.          lc.client = mc;
  471.          name = ["",Math.floor(new Date().getTime()),Math.floor(Math.random() * 999999)].join("_");
  472.          lc.allowDomain("*","localhost");
  473.          lc.allowInsecureDomain("*","localhost");
  474.          lc.connect(name);
  475.          mc.lc = lc;
  476.          mc.lcName = name;
  477.          lv.lc = name;
  478.          lv.st = getTimer();
  479.          loader = new Loader();
  480.          g = function(param1:Object):void
  481.          {
  482.             param1.target.removeEventListener(param1.type,arguments.callee);
  483.             MochiAd.unload(clip);
  484.          };
  485.          loader.contentLoaderInfo.addEventListener(Event.UNLOAD,g);
  486.          req = new URLRequest(server + ".swf");
  487.          req.contentType = "application/x-www-form-urlencoded";
  488.          req.method = URLRequestMethod.POST;
  489.          req.data = lv;
  490.          loader.load(req);
  491.          mc.addChild(loader);
  492.          mc._mochiad_ctr = loader;
  493.          return mc;
  494.       }
  495.       
  496.       public static function runMethod(param1:Object, param2:String, param3:Array) : Object
  497.       {
  498.          var _loc4_:Array = param2.split(".");
  499.          var _loc5_:Number = 0;
  500.          while(_loc5_ < _loc4_.length - 1)
  501.          {
  502.             if(param1[_loc4_[_loc5_]] == undefined || param1[_loc4_[_loc5_]] == null)
  503.             {
  504.                return undefined;
  505.             }
  506.             param1 = param1[_loc4_[_loc5_]];
  507.             _loc5_++;
  508.          }
  509.          if(typeof param1[_loc4_[_loc5_]] == "function")
  510.          {
  511.             return param1[_loc4_[_loc5_]].apply(param1,param3);
  512.          }
  513.          return undefined;
  514.       }
  515.       
  516.       public static function createEmptyMovieClip(param1:Object, param2:String, param3:Number) : MovieClip
  517.       {
  518.          var _loc4_:MovieClip = new MovieClip();
  519.          if(false && param3)
  520.          {
  521.             param1.addChildAt(_loc4_,param3);
  522.          }
  523.          else
  524.          {
  525.             param1.addChild(_loc4_);
  526.          }
  527.          param1[param2] = _loc4_;
  528.          _loc4_["_name"] = param2;
  529.          return _loc4_;
  530.       }
  531.       
  532.       public static function _getRes(param1:Object, param2:Object) : Array
  533.       {
  534.          var _loc6_:Array = null;
  535.          var _loc3_:Object = param2.getBounds(param2.root);
  536.          var _loc4_:Number = 0;
  537.          var _loc5_:Number = 0;
  538.          if(typeof param1.res != "undefined")
  539.          {
  540.             _loc6_ = param1.res.split("x");
  541.             _loc4_ = parseFloat(_loc6_[0]);
  542.             _loc5_ = parseFloat(_loc6_[1]);
  543.          }
  544.          else
  545.          {
  546.             _loc4_ = _loc3_.xMax - _loc3_.xMin;
  547.             _loc5_ = _loc3_.yMax - _loc3_.yMin;
  548.          }
  549.          if(_loc4_ == 0 || _loc5_ == 0)
  550.          {
  551.             _loc4_ = param2.stage.stageWidth;
  552.             _loc5_ = param2.stage.stageHeight;
  553.          }
  554.          return [_loc4_,_loc5_];
  555.       }
  556.       
  557.       public static function adShowing(param1:Object) : void
  558.       {
  559.          param1.origFrameRate = param1.stage.frameRate;
  560.          param1.stage.frameRate = 30;
  561.       }
  562.       
  563.       public static function getValue(param1:Object, param2:String) : Object
  564.       {
  565.          var _loc3_:Array = param2.split(".");
  566.          var _loc4_:Number = 0;
  567.          while(_loc4_ < _loc3_.length - 1)
  568.          {
  569.             if(param1[_loc3_[_loc4_]] == undefined || param1[_loc3_[_loc4_]] == null)
  570.             {
  571.                return undefined;
  572.             }
  573.             param1 = param1[_loc3_[_loc4_]];
  574.             _loc4_++;
  575.          }
  576.          return param1[_loc3_[_loc4_]];
  577.       }
  578.       
  579.       public static function rpc(param1:Object, param2:Number, param3:Object) : void
  580.       {
  581.          var _loc4_:Object = null;
  582.          var _loc5_:Object = null;
  583.          switch(param3.id)
  584.          {
  585.             case "setValue":
  586.                MochiAd.setValue(param1,param3.objectName,param3.value);
  587.                break;
  588.             case "getValue":
  589.                _loc4_ = MochiAd.getValue(param1,param3.objectName);
  590.                param1._mochiad.lc.send(param1._mochiad._containerLCName,"rpcResult",param2,_loc4_);
  591.                break;
  592.             case "runMethod":
  593.                _loc5_ = MochiAd.runMethod(param1,param3.method,param3.args);
  594.                param1._mochiad.lc.send(param1._mochiad._containerLCName,"rpcResult",param2,_loc5_);
  595.                break;
  596.             default:
  597.                trace("[mochiads rpc] unknown rpc id: " + param3.id);
  598.          }
  599.       }
  600.       
  601.       public static function setValue(param1:Object, param2:String, param3:Object) : void
  602.       {
  603.          var _loc4_:Array = param2.split(".");
  604.          var _loc5_:Number = 0;
  605.          while(_loc5_ < _loc4_.length - 1)
  606.          {
  607.             if(param1[_loc4_[_loc5_]] == undefined || param1[_loc4_[_loc5_]] == null)
  608.             {
  609.                return;
  610.             }
  611.             param1 = param1[_loc4_[_loc5_]];
  612.             _loc5_++;
  613.          }
  614.          param1[_loc4_[_loc5_]] = param3;
  615.       }
  616.       
  617.       public static function showPreGameAd(param1:Object) : void
  618.       {
  619.          var clip:Object = null;
  620.          var mc:MovieClip = null;
  621.          var chk:MovieClip = null;
  622.          var complete:Boolean = false;
  623.          var unloaded:Boolean = false;
  624.          var sendHostProgress:Boolean = false;
  625.          var r:MovieClip = null;
  626.          var options:Object = param1;
  627.          var DEFAULTS:Object = {
  628.             "ad_timeout":3000,
  629.             "fadeout_time":250,
  630.             "regpt":"o",
  631.             "method":"showPreloaderAd",
  632.             "color":16747008,
  633.             "background":16777161,
  634.             "outline":13994812,
  635.             "no_progress_bar":false,
  636.             "ad_started":function():void
  637.             {
  638.                if(this.clip is MovieClip)
  639.                {
  640.                   this.clip.stop();
  641.                   return;
  642.                }
  643.                throw new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip.  If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.");
  644.             },
  645.             "ad_finished":function():void
  646.             {
  647.                if(this.clip is MovieClip)
  648.                {
  649.                   this.clip.play();
  650.                   return;
  651.                }
  652.                throw new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip.  If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers.");
  653.             },
  654.             "ad_loaded":function(param1:Number, param2:Number):void
  655.             {
  656.             },
  657.             "ad_failed":function():void
  658.             {
  659.                trace("[MochiAd] Couldn\'t load an ad, make sure your game\'s local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
  660.             },
  661.             "ad_skipped":function():void
  662.             {
  663.             },
  664.             "ad_progress":function(param1:Number):void
  665.             {
  666.             }
  667.          };
  668.          options = MochiAd._parseOptions(options,DEFAULTS);
  669.          if("c862232051e0a94e1c3609b3916ddb17".substr(0) == "dfeada81ac97cde83665f81c12da7def")
  670.          {
  671.             options.ad_started();
  672.             setTimeout(options.ad_finished,100);
  673.             return;
  674.          }
  675.          clip = options.clip;
  676.          var ad_msec:Number = 11000;
  677.          var ad_timeout:Number = options.ad_timeout;
  678.          delete options.ad_timeout;
  679.          var fadeout_time:Number = options.fadeout_time;
  680.          delete options.fadeout_time;
  681.          if(!MochiAd.load(options))
  682.          {
  683.             options.ad_failed();
  684.             options.ad_finished();
  685.             return;
  686.          }
  687.          options.ad_started();
  688.          mc = clip._mochiad;
  689.          mc["onUnload"] = function():void
  690.          {
  691.             MochiAd._cleanup(mc);
  692.             var fn:Function = function():void
  693.             {
  694.                options.ad_finished();
  695.             };
  696.             setTimeout(fn,100);
  697.          };
  698.          var wh:Array = MochiAd._getRes(options,clip);
  699.          var w:Number = wh[0];
  700.          var h:Number = wh[1];
  701.          mc.x = w * 0.5;
  702.          mc.y = h * 0.5;
  703.          chk = createEmptyMovieClip(mc,"_mochiad_wait",3);
  704.          chk.x = w * -0.5;
  705.          chk.y = h * -0.5;
  706.          var bar:MovieClip = createEmptyMovieClip(chk,"_mochiad_bar",4);
  707.          if(options.no_progress_bar)
  708.          {
  709.             bar.visible = false;
  710.             delete options.no_progress_bar;
  711.          }
  712.          else
  713.          {
  714.             bar.x = 10;
  715.             bar.y = h - 20;
  716.          }
  717.          var bar_color:Number = options.color;
  718.          delete options.color;
  719.          var bar_background:Number = options.background;
  720.          delete options.background;
  721.          var bar_outline:Number = options.outline;
  722.          delete options.outline;
  723.          var backing_mc:MovieClip = createEmptyMovieClip(bar,"_outline",1);
  724.          var backing:Object = backing_mc.graphics;
  725.          backing.beginFill(bar_background);
  726.          backing.moveTo(0,0);
  727.          backing.lineTo(w - 20,0);
  728.          backing.lineTo(w - 20,10);
  729.          backing.lineTo(0,10);
  730.          backing.lineTo(0,0);
  731.          backing.endFill();
  732.          var inside_mc:MovieClip = createEmptyMovieClip(bar,"_inside",2);
  733.          var inside:Object = inside_mc.graphics;
  734.          inside.beginFill(bar_color);
  735.          inside.moveTo(0,0);
  736.          inside.lineTo(w - 20,0);
  737.          inside.lineTo(w - 20,10);
  738.          inside.lineTo(0,10);
  739.          inside.lineTo(0,0);
  740.          inside.endFill();
  741.          inside_mc.scaleX = 0;
  742.          var outline_mc:MovieClip = createEmptyMovieClip(bar,"_outline",3);
  743.          var outline:Object = outline_mc.graphics;
  744.          outline.lineStyle(0,bar_outline,100);
  745.          outline.moveTo(0,0);
  746.          outline.lineTo(w - 20,0);
  747.          outline.lineTo(w - 20,10);
  748.          outline.lineTo(0,10);
  749.          outline.lineTo(0,0);
  750.          chk.ad_msec = ad_msec;
  751.          chk.ad_timeout = ad_timeout;
  752.          chk.started = getTimer();
  753.          chk.showing = false;
  754.          chk.last_pcnt = 0;
  755.          chk.fadeout_time = fadeout_time;
  756.          chk.fadeFunction = function():void
  757.          {
  758.             var _loc1_:Number = 100 * (1 - (getTimer() - this.fadeout_start) / this.fadeout_time);
  759.             if(_loc1_ > 0)
  760.             {
  761.                this.parent.alpha = _loc1_ * 0.01;
  762.             }
  763.             else
  764.             {
  765.                MochiAd.unload(clip);
  766.                delete this["onEnterFrame"];
  767.             }
  768.          };
  769.          complete = false;
  770.          unloaded = false;
  771.          var f:Function = function(param1:Event):void
  772.          {
  773.             param1.target.removeEventListener(param1.type,arguments.callee);
  774.             complete = true;
  775.             if(unloaded)
  776.             {
  777.                MochiAd.unload(clip);
  778.             }
  779.          };
  780.          clip.loaderInfo.addEventListener(Event.COMPLETE,f);
  781.          if(clip.root is MovieClip)
  782.          {
  783.             r = clip.root as MovieClip;
  784.             if(r.framesLoaded >= r.totalFrames)
  785.             {
  786.                complete = true;
  787.             }
  788.          }
  789.          mc.unloadAd = function():void
  790.          {
  791.             unloaded = true;
  792.             if(complete)
  793.             {
  794.                MochiAd.unload(clip);
  795.             }
  796.          };
  797.          mc.adLoaded = options.ad_loaded;
  798.          mc.adSkipped = options.ad_skipped;
  799.          mc.adjustProgress = function(param1:Number):void
  800.          {
  801.             var _loc2_:Object = mc._mochiad_wait;
  802.             _loc2_.server_control = true;
  803.             _loc2_.showing = true;
  804.             _loc2_.started = getTimer();
  805.             _loc2_.ad_msec = param1;
  806.          };
  807.          mc.rpc = function(param1:Number, param2:Object):void
  808.          {
  809.             MochiAd.rpc(clip,param1,param2);
  810.          };
  811.          mc.rpcTestFn = function(param1:String):Object
  812.          {
  813.             trace("[MOCHIAD rpcTestFn] " + param1);
  814.             return param1;
  815.          };
  816.          mc.regContLC = function(param1:String):void
  817.          {
  818.             mc._containerLCName = param1;
  819.          };
  820.          sendHostProgress = false;
  821.          mc.sendHostLoadProgress = function(param1:String):void
  822.          {
  823.             sendHostProgress = true;
  824.          };
  825.          chk["onEnterFrame"] = function():void
  826.          {
  827.             var _loc11_:Number = NaN;
  828.             if(!this.parent || !this.parent.parent)
  829.             {
  830.                delete this["onEnterFrame"];
  831.                return;
  832.             }
  833.             var _loc1_:Object = this.parent.parent.root;
  834.             var _loc2_:Object = this.parent._mochiad_ctr;
  835.             var _loc3_:Number = getTimer() - this.started;
  836.             var _loc4_:Boolean = false;
  837.             var _loc5_:Number = _loc1_.loaderInfo.bytesTotal;
  838.             var _loc6_:Number = _loc1_.loaderInfo.bytesLoaded;
  839.             if(complete)
  840.             {
  841.                _loc5_ = _loc6_ = Math.max(1,_loc6_);
  842.             }
  843.             var _loc7_:Number = 100 * _loc6_ / _loc5_;
  844.             var _loc8_:Number = 100 * _loc3_ / chk.ad_msec;
  845.             var _loc9_:Object = this._mochiad_bar._inside;
  846.             var _loc10_:Number = Math.min(100,Math.min(Number(_loc7_) || Number(0),_loc8_));
  847.             _loc10_ = Math.max(this.last_pcnt,_loc10_);
  848.             this.last_pcnt = _loc10_;
  849.             _loc9_.scaleX = _loc10_ * 0.01;
  850.             options.ad_progress(_loc10_);
  851.             if(sendHostProgress)
  852.             {
  853.                clip._mochiad.lc.send(clip._mochiad._containerLCName,"notify",{
  854.                   "id":"hostLoadPcnt",
  855.                   "pcnt":_loc7_
  856.                });
  857.                if(_loc7_ == 100)
  858.                {
  859.                   sendHostProgress = false;
  860.                }
  861.             }
  862.             if(!chk.showing)
  863.             {
  864.                if((_loc11_ = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal) > 0)
  865.                {
  866.                   chk.showing = true;
  867.                   chk.started = getTimer();
  868.                   MochiAd.adShowing(clip);
  869.                }
  870.                else if(_loc3_ > chk.ad_timeout && _loc7_ == 100)
  871.                {
  872.                   options.ad_failed();
  873.                   _loc4_ = true;
  874.                }
  875.             }
  876.             if(_loc3_ > chk.ad_msec)
  877.             {
  878.                _loc4_ = true;
  879.             }
  880.             if(complete && _loc4_)
  881.             {
  882.                if(this.server_control)
  883.                {
  884.                   delete this.onEnterFrame;
  885.                }
  886.                else
  887.                {
  888.                   this.fadeout_start = getTimer();
  889.                   this.onEnterFrame = chk.fadeFunction;
  890.                }
  891.             }
  892.          };
  893.          doOnEnterFrame(chk);
  894.       }
  895.       
  896.       public static function showPreloaderAd(param1:Object) : void
  897.       {
  898.          trace("[MochiAd] DEPRECATED: showPreloaderAd was renamed to showPreGameAd in 2.0");
  899.          MochiAd.showPreGameAd(param1);
  900.       }
  901.       
  902.       public static function showTimedAd(param1:Object) : void
  903.       {
  904.          trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0");
  905.          MochiAd.showInterLevelAd(param1);
  906.       }
  907.       
  908.       public static function doOnEnterFrame(param1:MovieClip) : void
  909.       {
  910.          var mc:MovieClip = param1;
  911.          var f:Function = function(param1:Object):void
  912.          {
  913.             if("onEnterFrame" in mc && mc.onEnterFrame)
  914.             {
  915.                mc.onEnterFrame();
  916.             }
  917.             else
  918.             {
  919.                param1.target.removeEventListener(param1.type,arguments.callee);
  920.             }
  921.          };
  922.          mc.addEventListener(Event.ENTER_FRAME,f);
  923.       }
  924.    }
  925. }
  926.