home *** CD-ROM | disk | FTP | other *** search
/ 404 Jogos / CLJG.iso / Puzzle / filler.swf / scripts / mx / effects / EffectManager.as < prev    next >
Encoding:
Text File  |  2008-09-02  |  18.2 KB  |  572 lines

  1. package mx.effects
  2. {
  3.    import flash.display.DisplayObject;
  4.    import flash.display.DisplayObjectContainer;
  5.    import flash.events.Event;
  6.    import flash.events.EventDispatcher;
  7.    import flash.events.FocusEvent;
  8.    import flash.system.ApplicationDomain;
  9.    import mx.core.Application;
  10.    import mx.core.EventPriority;
  11.    import mx.core.IDeferredInstantiationUIComponent;
  12.    import mx.core.IFlexDisplayObject;
  13.    import mx.core.IUIComponent;
  14.    import mx.core.UIComponent;
  15.    import mx.core.UIComponentCachePolicy;
  16.    import mx.core.mx_internal;
  17.    import mx.events.EffectEvent;
  18.    import mx.events.FlexEvent;
  19.    import mx.events.MoveEvent;
  20.    import mx.events.ResizeEvent;
  21.    import mx.resources.ResourceBundle;
  22.    
  23.    use namespace mx_internal;
  24.    
  25.    public class EffectManager extends EventDispatcher
  26.    {
  27.       
  28.       private static var resourceIncorrectTrigger:String;
  29.       
  30.       mx_internal static const VERSION:String = "2.0.1.0";
  31.       
  32.       mx_internal static var effectsPlaying:Array = [];
  33.       
  34.       private static var targetsInfo:Array = [];
  35.       
  36.       private static var effectTriggersForEvent:Object = {};
  37.       
  38.       mx_internal static var lastEffectCreated:Effect;
  39.       
  40.       private static var eventHandlingSuspendCount:Number = 0;
  41.       
  42.       private static var eventsForEffectTriggers:Object = {};
  43.       
  44.       private static var packageResources:ResourceBundle = ResourceBundle.getResourceBundle("effects",ApplicationDomain.currentDomain);
  45.       
  46.       {
  47.          loadResources();
  48.       }
  49.       
  50.       public function EffectManager()
  51.       {
  52.          super();
  53.       }
  54.       
  55.       private static function createAndPlayEffect(param1:Event, param2:Object) : void
  56.       {
  57.          var _loc3_:Effect = null;
  58.          var _loc4_:int = 0;
  59.          var _loc5_:int = 0;
  60.          var _loc6_:int = 0;
  61.          var _loc7_:int = 0;
  62.          var _loc8_:Array = null;
  63.          var _loc9_:String = null;
  64.          var _loc10_:Array = null;
  65.          var _loc11_:Array = null;
  66.          var _loc12_:Array = null;
  67.          var _loc13_:Array = null;
  68.          var _loc14_:EffectInstance = null;
  69.          _loc3_ = mx_internal::createEffectForType(param2,param1.type);
  70.          if(!_loc3_)
  71.          {
  72.             return;
  73.          }
  74.          if(_loc3_ is Zoom && param1.type == MoveEvent.MOVE)
  75.          {
  76.             throw new Error(resourceIncorrectTrigger);
  77.          }
  78.          if(param2.initialized == false)
  79.          {
  80.             if((_loc9_ = param1.type) == MoveEvent.MOVE || _loc9_ == ResizeEvent.RESIZE || _loc9_ == FlexEvent.SHOW || _loc9_ == FlexEvent.HIDE || _loc9_ == Event.CHANGE)
  81.             {
  82.                _loc3_ = null;
  83.                return;
  84.             }
  85.          }
  86.          if(_loc3_.target is IUIComponent)
  87.          {
  88.             if((Boolean(_loc10_ = IUIComponent(_loc3_.target).tweeningProperties)) && _loc10_.length > 0)
  89.             {
  90.                _loc11_ = _loc3_.getAffectedProperties();
  91.                _loc4_ = int(_loc10_.length);
  92.                _loc6_ = int(_loc11_.length);
  93.                _loc5_ = 0;
  94.                while(_loc5_ < _loc4_)
  95.                {
  96.                   _loc7_ = 0;
  97.                   while(_loc7_ < _loc6_)
  98.                   {
  99.                      if(_loc10_[_loc5_] == _loc11_[_loc7_])
  100.                      {
  101.                         _loc3_ = null;
  102.                         return;
  103.                      }
  104.                      _loc7_++;
  105.                   }
  106.                   _loc5_++;
  107.                }
  108.             }
  109.          }
  110.          if(_loc3_.target is UIComponent && UIComponent(_loc3_.target).mx_internal::isEffectStarted)
  111.          {
  112.             _loc12_ = _loc3_.getAffectedProperties();
  113.             _loc5_ = 0;
  114.             while(_loc5_ < _loc12_.length)
  115.             {
  116.                if((_loc13_ = _loc3_.target.mx_internal::getEffectsForProperty(_loc12_[_loc5_])).length > 0)
  117.                {
  118.                   if(param1.type == ResizeEvent.RESIZE)
  119.                   {
  120.                      return;
  121.                   }
  122.                   _loc7_ = 0;
  123.                   while(_loc7_ < _loc13_.length)
  124.                   {
  125.                      _loc14_ = _loc13_[_loc7_];
  126.                      if(param1.type == FlexEvent.SHOW && _loc14_.mx_internal::hideOnEffectEnd)
  127.                      {
  128.                         _loc14_.target.removeEventListener(FlexEvent.SHOW,_loc14_.mx_internal::eventHandler);
  129.                         _loc14_.mx_internal::hideOnEffectEnd = false;
  130.                      }
  131.                      _loc14_.end();
  132.                      _loc7_++;
  133.                   }
  134.                }
  135.                _loc5_++;
  136.             }
  137.          }
  138.          _loc3_.mx_internal::initEvent = param1;
  139.          _loc3_.addEventListener(EffectEvent.EFFECT_END,EffectManager.mx_internal::effectEndHandler);
  140.          mx_internal::lastEffectCreated = _loc3_;
  141.          _loc4_ = int((_loc8_ = _loc3_.play()).length);
  142.          _loc5_ = 0;
  143.          while(_loc5_ < _loc4_)
  144.          {
  145.             mx_internal::effectsPlaying.push(new EffectNode(_loc3_,_loc8_[_loc5_]));
  146.             _loc5_++;
  147.          }
  148.          if(_loc3_.suspendBackgroundProcessing)
  149.          {
  150.             UIComponent.suspendBackgroundProcessing();
  151.          }
  152.       }
  153.       
  154.       public static function suspendEventHandling() : void
  155.       {
  156.          ++eventHandlingSuspendCount;
  157.       }
  158.       
  159.       mx_internal static function registerEffectTrigger(param1:String, param2:String) : void
  160.       {
  161.          var _loc3_:Number = NaN;
  162.          if(param1 != "")
  163.          {
  164.             if(param2 == "")
  165.             {
  166.                _loc3_ = param1.length;
  167.                if(_loc3_ > 6 && param1.substring(_loc3_ - 6) == "Effect")
  168.                {
  169.                   param2 = param1.substring(0,_loc3_ - 6);
  170.                }
  171.             }
  172.             if(param2 != "")
  173.             {
  174.                effectTriggersForEvent[param2] = param1;
  175.                eventsForEffectTriggers[param1] = param2;
  176.             }
  177.          }
  178.       }
  179.       
  180.       private static function removedEffectHandler(param1:DisplayObject, param2:DisplayObjectContainer, param3:int, param4:Event) : void
  181.       {
  182.          suspendEventHandling();
  183.          param2.addChildAt(param1,param3);
  184.          resumeEventHandling();
  185.          createAndPlayEffect(param4,param1);
  186.       }
  187.       
  188.       mx_internal static function endVectorEffect(param1:IUIComponent) : void
  189.       {
  190.          cacheOrUncacheTargetAsBitmap(param1,false,false);
  191.       }
  192.       
  193.       public static function endEffectsForTarget(param1:IUIComponent) : void
  194.       {
  195.          var _loc2_:int = 0;
  196.          var _loc3_:int = 0;
  197.          var _loc4_:EffectInstance = null;
  198.          _loc2_ = int(mx_internal::effectsPlaying.length);
  199.          _loc3_ = _loc2_ - 1;
  200.          while(_loc3_ >= 0)
  201.          {
  202.             if((_loc4_ = mx_internal::effectsPlaying[_loc3_].instance).target == param1)
  203.             {
  204.                _loc4_.end();
  205.             }
  206.             _loc3_--;
  207.          }
  208.       }
  209.       
  210.       private static function cacheOrUncacheTargetAsBitmap(param1:IUIComponent, param2:Boolean = true, param3:Boolean = true) : void
  211.       {
  212.          var _loc4_:int = 0;
  213.          var _loc5_:int = 0;
  214.          var _loc6_:Object = null;
  215.          _loc6_ = null;
  216.          _loc4_ = int(targetsInfo.length);
  217.          _loc5_ = 0;
  218.          while(_loc5_ < _loc4_)
  219.          {
  220.             if(targetsInfo[_loc5_].target == param1)
  221.             {
  222.                _loc6_ = targetsInfo[_loc5_];
  223.                break;
  224.             }
  225.             _loc5_++;
  226.          }
  227.          if(!_loc6_)
  228.          {
  229.             _loc6_ = {
  230.                "target":param1,
  231.                "bitmapEffectsCount":0,
  232.                "vectorEffectsCount":0
  233.             };
  234.             targetsInfo.push(_loc6_);
  235.          }
  236.          if(param2)
  237.          {
  238.             if(param3)
  239.             {
  240.                ++_loc6_.bitmapEffectsCount;
  241.                if(_loc6_.vectorEffectsCount == 0 && param1 is IDeferredInstantiationUIComponent)
  242.                {
  243.                   IDeferredInstantiationUIComponent(param1).cacheHeuristic = true;
  244.                }
  245.             }
  246.             else if(_loc6_.vectorEffectsCount++ == 0 && param1 is IDeferredInstantiationUIComponent && IDeferredInstantiationUIComponent(param1).cachePolicy == UIComponentCachePolicy.AUTO)
  247.             {
  248.                param1.cacheAsBitmap = false;
  249.             }
  250.          }
  251.          else
  252.          {
  253.             if(param3)
  254.             {
  255.                if(_loc6_.bitmapEffectsCount != 0)
  256.                {
  257.                   --_loc6_.bitmapEffectsCount;
  258.                }
  259.                if(param1 is IDeferredInstantiationUIComponent)
  260.                {
  261.                   IDeferredInstantiationUIComponent(param1).cacheHeuristic = false;
  262.                }
  263.             }
  264.             else if(_loc6_.vectorEffectsCount != 0)
  265.             {
  266.                if(--_loc6_.vectorEffectsCount == 0 && _loc6_.bitmapEffectsCount != 0)
  267.                {
  268.                   _loc4_ = int(_loc6_.bitmapEffectsCount);
  269.                   _loc5_ = 0;
  270.                   while(_loc5_ < _loc4_)
  271.                   {
  272.                      if(param1 is IDeferredInstantiationUIComponent)
  273.                      {
  274.                         IDeferredInstantiationUIComponent(param1).cacheHeuristic = true;
  275.                      }
  276.                      _loc5_++;
  277.                   }
  278.                }
  279.             }
  280.             if(_loc6_.bitmapEffectsCount == 0 && _loc6_.vectorEffectsCount == 0)
  281.             {
  282.                _loc4_ = int(targetsInfo.length);
  283.                _loc5_ = 0;
  284.                while(_loc5_ < _loc4_)
  285.                {
  286.                   if(targetsInfo[_loc5_].target == param1)
  287.                   {
  288.                      targetsInfo.splice(_loc5_,1);
  289.                      break;
  290.                   }
  291.                   _loc5_++;
  292.                }
  293.             }
  294.          }
  295.       }
  296.       
  297.       mx_internal static function eventHandler(param1:Event) : void
  298.       {
  299.          var _loc2_:FocusEvent = null;
  300.          var _loc3_:DisplayObject = null;
  301.          var _loc4_:int = 0;
  302.          var _loc5_:DisplayObjectContainer = null;
  303.          var _loc6_:int = 0;
  304.          if(!(param1.currentTarget is IFlexDisplayObject))
  305.          {
  306.             return;
  307.          }
  308.          if(eventHandlingSuspendCount > 0)
  309.          {
  310.             return;
  311.          }
  312.          if(param1 is FocusEvent && (param1.type == FocusEvent.FOCUS_OUT || param1.type == FocusEvent.FOCUS_IN))
  313.          {
  314.             _loc2_ = FocusEvent(param1);
  315.             if(Boolean(_loc2_.relatedObject) && (_loc2_.currentTarget.contains(_loc2_.relatedObject) || _loc2_.currentTarget == _loc2_.relatedObject))
  316.             {
  317.                return;
  318.             }
  319.          }
  320.          if((param1.type == Event.ADDED || param1.type == Event.REMOVED) && param1.target != param1.currentTarget)
  321.          {
  322.             return;
  323.          }
  324.          if(param1.type == Event.REMOVED)
  325.          {
  326.             if(param1.target is UIComponent)
  327.             {
  328.                if(UIComponent(param1.target).initialized == false)
  329.                {
  330.                   return;
  331.                }
  332.                if(UIComponent(param1.target).mx_internal::isEffectStarted)
  333.                {
  334.                   _loc4_ = 0;
  335.                   while(_loc4_ < UIComponent(param1.target).mx_internal::_effectsStarted.length)
  336.                   {
  337.                      if(UIComponent(param1.target).mx_internal::_effectsStarted[_loc4_].triggerEvent.type == Event.REMOVED)
  338.                      {
  339.                         return;
  340.                      }
  341.                      _loc4_++;
  342.                   }
  343.                }
  344.             }
  345.             _loc3_ = param1.target as DisplayObject;
  346.             if(_loc3_ != null)
  347.             {
  348.                if((_loc5_ = _loc3_.parent as DisplayObjectContainer) != null)
  349.                {
  350.                   if((_loc6_ = _loc5_.getChildIndex(_loc3_)) >= 0)
  351.                   {
  352.                      if(_loc3_ is UIComponent)
  353.                      {
  354.                         UIComponent(_loc3_).callLater(removedEffectHandler,[_loc3_,_loc5_,_loc6_,param1]);
  355.                      }
  356.                   }
  357.                }
  358.             }
  359.          }
  360.          else
  361.          {
  362.             createAndPlayEffect(param1,param1.currentTarget);
  363.          }
  364.       }
  365.       
  366.       mx_internal static function endBitmapEffect(param1:IUIComponent) : void
  367.       {
  368.          cacheOrUncacheTargetAsBitmap(param1,false,true);
  369.       }
  370.       
  371.       private static function animateSameProperty(param1:Effect, param2:Effect, param3:EffectInstance) : Boolean
  372.       {
  373.          var _loc4_:Array = null;
  374.          var _loc5_:Array = null;
  375.          var _loc6_:int = 0;
  376.          var _loc7_:int = 0;
  377.          var _loc8_:int = 0;
  378.          var _loc9_:int = 0;
  379.          if(param1.target == param3.target)
  380.          {
  381.             _loc4_ = param1.getAffectedProperties();
  382.             _loc5_ = param2.getAffectedProperties();
  383.             _loc6_ = int(_loc4_.length);
  384.             _loc7_ = int(_loc5_.length);
  385.             _loc8_ = 0;
  386.             while(_loc8_ < _loc6_)
  387.             {
  388.                _loc9_ = 0;
  389.                while(_loc9_ < _loc7_)
  390.                {
  391.                   if(_loc4_[_loc8_] == _loc5_[_loc9_])
  392.                   {
  393.                      return true;
  394.                   }
  395.                   _loc9_++;
  396.                }
  397.                _loc8_++;
  398.             }
  399.          }
  400.          return false;
  401.       }
  402.       
  403.       private static function loadResources() : void
  404.       {
  405.          resourceIncorrectTrigger = packageResources.getString("incorrectTrigger");
  406.       }
  407.       
  408.       mx_internal static function effectEndHandler(param1:EffectEvent) : void
  409.       {
  410.          var _loc2_:IEffectInstance = null;
  411.          var _loc3_:int = 0;
  412.          var _loc4_:int = 0;
  413.          var _loc5_:DisplayObject = null;
  414.          var _loc6_:DisplayObjectContainer = null;
  415.          _loc2_ = param1.effectInstance;
  416.          _loc3_ = int(mx_internal::effectsPlaying.length);
  417.          _loc4_ = _loc3_ - 1;
  418.          while(_loc4_ >= 0)
  419.          {
  420.             if(mx_internal::effectsPlaying[_loc4_].instance == _loc2_)
  421.             {
  422.                mx_internal::effectsPlaying.splice(_loc4_,1);
  423.                break;
  424.             }
  425.             _loc4_--;
  426.          }
  427.          if(Object(_loc2_).hideOnEffectEnd == true)
  428.          {
  429.             _loc2_.target.removeEventListener(FlexEvent.SHOW,Object(_loc2_).eventHandler);
  430.             _loc2_.target.setVisible(false,true);
  431.          }
  432.          if(Boolean(_loc2_.triggerEvent) && _loc2_.triggerEvent.type == Event.REMOVED)
  433.          {
  434.             if((_loc5_ = _loc2_.target as DisplayObject) != null)
  435.             {
  436.                if((_loc6_ = _loc5_.parent as DisplayObjectContainer) != null)
  437.                {
  438.                   suspendEventHandling();
  439.                   _loc6_.removeChild(_loc5_);
  440.                   resumeEventHandling();
  441.                }
  442.             }
  443.          }
  444.          if(_loc2_.suspendBackgroundProcessing)
  445.          {
  446.             UIComponent.resumeBackgroundProcessing();
  447.          }
  448.       }
  449.       
  450.       mx_internal static function startBitmapEffect(param1:IUIComponent) : void
  451.       {
  452.          cacheOrUncacheTargetAsBitmap(param1,true,true);
  453.       }
  454.       
  455.       mx_internal static function setStyle(param1:String, param2:*) : void
  456.       {
  457.          var _loc3_:String = null;
  458.          _loc3_ = String(eventsForEffectTriggers[param1]);
  459.          if(_loc3_ != null && _loc3_ != "")
  460.          {
  461.             param2.addEventListener(_loc3_,EffectManager.mx_internal::eventHandler,false,EventPriority.EFFECT);
  462.          }
  463.       }
  464.       
  465.       mx_internal static function getEventForEffectTrigger(param1:String) : String
  466.       {
  467.          var effectTrigger:String = param1;
  468.          if(eventsForEffectTriggers)
  469.          {
  470.             try
  471.             {
  472.                return eventsForEffectTriggers[effectTrigger];
  473.             }
  474.             catch(e:Error)
  475.             {
  476.                return "";
  477.             }
  478.          }
  479.          else
  480.          {
  481.             return "";
  482.          }
  483.       }
  484.       
  485.       mx_internal static function createEffectForType(param1:Object, param2:String) : Effect
  486.       {
  487.          var trigger:String = null;
  488.          var value:Object = null;
  489.          var effectClass:Class = null;
  490.          var cls:Class = null;
  491.          var effectObj:Effect = null;
  492.          var doc:Object = null;
  493.          var target:Object = param1;
  494.          var type:String = param2;
  495.          trigger = String(effectTriggersForEvent[type]);
  496.          if(trigger == "")
  497.          {
  498.             trigger = type + "Effect";
  499.          }
  500.          value = target.getStyle(trigger);
  501.          if(!value)
  502.          {
  503.             return null;
  504.          }
  505.          if(value is Class)
  506.          {
  507.             cls = Class(value);
  508.             return new cls(target);
  509.          }
  510.          try
  511.          {
  512.             if(value is String)
  513.             {
  514.                doc = target.parentDocument;
  515.                if(!doc)
  516.                {
  517.                   doc = Application.application;
  518.                }
  519.                effectObj = doc[value];
  520.             }
  521.             else if(value is Effect)
  522.             {
  523.                effectObj = Effect(value);
  524.             }
  525.             if(effectObj)
  526.             {
  527.                effectObj.target = target;
  528.                return effectObj;
  529.             }
  530.          }
  531.          catch(e:Error)
  532.          {
  533.          }
  534.          effectClass = Class(target.systemManager.getDefinitionByName("mx.effects." + value));
  535.          if(effectClass)
  536.          {
  537.             return new effectClass(target);
  538.          }
  539.          return null;
  540.       }
  541.       
  542.       public static function resumeEventHandling() : void
  543.       {
  544.          --eventHandlingSuspendCount;
  545.       }
  546.       
  547.       mx_internal static function startVectorEffect(param1:IUIComponent) : void
  548.       {
  549.          cacheOrUncacheTargetAsBitmap(param1,true,false);
  550.       }
  551.    }
  552. }
  553.  
  554. import mx.effects.Effect;
  555. import mx.effects.EffectInstance;
  556.  
  557. class EffectNode
  558. {
  559.     
  560.    
  561.    public var instance:EffectInstance;
  562.    
  563.    public var factory:Effect;
  564.    
  565.    public function EffectNode(param1:Effect, param2:EffectInstance)
  566.    {
  567.       super();
  568.       this.factory = param1;
  569.       this.instance = param2;
  570.    }
  571. }
  572.