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