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