home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2012 April / ME_04_2012.iso / Video-Tutorial / iPhoto / media / player.swf / scripts / mx / effects / EffectInstance.as < prev    next >
Encoding:
Text File  |  2011-11-11  |  11.8 KB  |  399 lines

  1. package mx.effects
  2. {
  3.    import flash.events.Event;
  4.    import flash.events.EventDispatcher;
  5.    import flash.events.IEventDispatcher;
  6.    import flash.events.TimerEvent;
  7.    import flash.utils.Timer;
  8.    import flash.utils.getTimer;
  9.    import mx.core.UIComponent;
  10.    import mx.core.mx_internal;
  11.    import mx.effects.effectClasses.PropertyChanges;
  12.    import mx.events.EffectEvent;
  13.    import mx.events.FlexEvent;
  14.    import mx.utils.NameUtil;
  15.    
  16.    use namespace mx_internal;
  17.    
  18.    public class EffectInstance extends EventDispatcher implements IEffectInstance
  19.    {
  20.       mx_internal static const VERSION:String = "4.5.0.20967";
  21.       
  22.       mx_internal var delayTimer:Timer;
  23.       
  24.       private var delayStartTime:Number = 0;
  25.       
  26.       private var delayElapsedTime:Number = 0;
  27.       
  28.       mx_internal var durationExplicitlySet:Boolean = false;
  29.       
  30.       mx_internal var hideOnEffectEnd:Boolean = false;
  31.       
  32.       mx_internal var parentCompositeEffectInstance:EffectInstance;
  33.       
  34.       protected var playCount:int = 0;
  35.       
  36.       mx_internal var stopRepeat:Boolean = false;
  37.       
  38.       private var _duration:Number = 500;
  39.       
  40.       private var _effect:IEffect;
  41.       
  42.       private var _effectTargetHost:IEffectTargetHost;
  43.       
  44.       private var _hideFocusRing:Boolean;
  45.       
  46.       private var _playReversed:Boolean;
  47.       
  48.       private var _propertyChanges:PropertyChanges;
  49.       
  50.       private var _repeatCount:int = 0;
  51.       
  52.       private var _repeatDelay:int = 0;
  53.       
  54.       private var _startDelay:int = 0;
  55.       
  56.       private var _suspendBackgroundProcessing:Boolean = false;
  57.       
  58.       private var _target:Object;
  59.       
  60.       private var _triggerEvent:Event;
  61.       
  62.       public function EffectInstance(param1:Object)
  63.       {
  64.          super();
  65.          this.target = param1;
  66.       }
  67.       
  68.       mx_internal function get actualDuration() : Number
  69.       {
  70.          var _loc1_:Number = NaN;
  71.          if(this.repeatCount > 0)
  72.          {
  73.             _loc1_ = this.duration * this.repeatCount + this.repeatDelay * (this.repeatCount - 1) + this.startDelay;
  74.          }
  75.          return _loc1_;
  76.       }
  77.       
  78.       public function get className() : String
  79.       {
  80.          return NameUtil.getUnqualifiedClassName(this);
  81.       }
  82.       
  83.       public function get duration() : Number
  84.       {
  85.          if(!this.mx_internal::durationExplicitlySet && Boolean(this.mx_internal::parentCompositeEffectInstance))
  86.          {
  87.             return this.mx_internal::parentCompositeEffectInstance.duration;
  88.          }
  89.          return this._duration;
  90.       }
  91.       
  92.       public function set duration(param1:Number) : void
  93.       {
  94.          this.mx_internal::durationExplicitlySet = true;
  95.          this._duration = param1;
  96.       }
  97.       
  98.       public function get effect() : IEffect
  99.       {
  100.          return this._effect;
  101.       }
  102.       
  103.       public function set effect(param1:IEffect) : void
  104.       {
  105.          this._effect = param1;
  106.       }
  107.       
  108.       public function get effectTargetHost() : IEffectTargetHost
  109.       {
  110.          return this._effectTargetHost;
  111.       }
  112.       
  113.       public function set effectTargetHost(param1:IEffectTargetHost) : void
  114.       {
  115.          this._effectTargetHost = param1;
  116.       }
  117.       
  118.       public function get hideFocusRing() : Boolean
  119.       {
  120.          return this._hideFocusRing;
  121.       }
  122.       
  123.       public function set hideFocusRing(param1:Boolean) : void
  124.       {
  125.          this._hideFocusRing = param1;
  126.       }
  127.       
  128.       public function get playheadTime() : Number
  129.       {
  130.          return Math.max(this.playCount - 1,0) * (this.duration + this.repeatDelay) + (this.mx_internal::playReversed ? 0 : this.startDelay);
  131.       }
  132.       
  133.       public function set playheadTime(param1:Number) : void
  134.       {
  135.          if(Boolean(this.mx_internal::delayTimer) && this.mx_internal::delayTimer.running)
  136.          {
  137.             this.mx_internal::delayTimer.reset();
  138.             if(param1 < this.startDelay)
  139.             {
  140.                this.mx_internal::delayTimer = new Timer(this.startDelay - param1,1);
  141.                this.delayStartTime = getTimer();
  142.                this.mx_internal::delayTimer.addEventListener(TimerEvent.TIMER,this.delayTimerHandler);
  143.                this.mx_internal::delayTimer.start();
  144.             }
  145.             else
  146.             {
  147.                this.playCount = 0;
  148.                this.play();
  149.             }
  150.          }
  151.       }
  152.       
  153.       mx_internal function get playReversed() : Boolean
  154.       {
  155.          return this._playReversed;
  156.       }
  157.       
  158.       mx_internal function set playReversed(param1:Boolean) : void
  159.       {
  160.          this._playReversed = param1;
  161.       }
  162.       
  163.       public function get propertyChanges() : PropertyChanges
  164.       {
  165.          return this._propertyChanges;
  166.       }
  167.       
  168.       public function set propertyChanges(param1:PropertyChanges) : void
  169.       {
  170.          this._propertyChanges = param1;
  171.       }
  172.       
  173.       public function get repeatCount() : int
  174.       {
  175.          return this._repeatCount;
  176.       }
  177.       
  178.       public function set repeatCount(param1:int) : void
  179.       {
  180.          this._repeatCount = param1;
  181.       }
  182.       
  183.       public function get repeatDelay() : int
  184.       {
  185.          return this._repeatDelay;
  186.       }
  187.       
  188.       public function set repeatDelay(param1:int) : void
  189.       {
  190.          this._repeatDelay = param1;
  191.       }
  192.       
  193.       public function get startDelay() : int
  194.       {
  195.          return this._startDelay;
  196.       }
  197.       
  198.       public function set startDelay(param1:int) : void
  199.       {
  200.          this._startDelay = param1;
  201.       }
  202.       
  203.       public function get suspendBackgroundProcessing() : Boolean
  204.       {
  205.          return this._suspendBackgroundProcessing;
  206.       }
  207.       
  208.       public function set suspendBackgroundProcessing(param1:Boolean) : void
  209.       {
  210.          this._suspendBackgroundProcessing = param1;
  211.       }
  212.       
  213.       public function get target() : Object
  214.       {
  215.          return this._target;
  216.       }
  217.       
  218.       public function set target(param1:Object) : void
  219.       {
  220.          this._target = param1;
  221.       }
  222.       
  223.       public function get triggerEvent() : Event
  224.       {
  225.          return this._triggerEvent;
  226.       }
  227.       
  228.       public function set triggerEvent(param1:Event) : void
  229.       {
  230.          this._triggerEvent = param1;
  231.       }
  232.       
  233.       public function initEffect(param1:Event) : void
  234.       {
  235.          this.triggerEvent = param1;
  236.          switch(param1.type)
  237.          {
  238.             case "resizeStart":
  239.             case "resizeEnd":
  240.                if(!this.mx_internal::durationExplicitlySet)
  241.                {
  242.                   this.duration = 250;
  243.                }
  244.                break;
  245.             case FlexEvent.HIDE:
  246.                this.target.setVisible(true,true);
  247.                this.mx_internal::hideOnEffectEnd = true;
  248.                this.target.addEventListener(FlexEvent.SHOW,this.mx_internal::eventHandler);
  249.          }
  250.       }
  251.       
  252.       public function startEffect() : void
  253.       {
  254.          EffectManager.mx_internal::effectStarted(this);
  255.          if(this.target is UIComponent)
  256.          {
  257.             UIComponent(this.target).effectStarted(this);
  258.          }
  259.          if(this.startDelay > 0 && !this.mx_internal::playReversed)
  260.          {
  261.             this.mx_internal::delayTimer = new Timer(this.startDelay,1);
  262.             this.delayStartTime = getTimer();
  263.             this.mx_internal::delayTimer.addEventListener(TimerEvent.TIMER,this.delayTimerHandler);
  264.             this.mx_internal::delayTimer.start();
  265.          }
  266.          else
  267.          {
  268.             this.play();
  269.          }
  270.       }
  271.       
  272.       public function play() : void
  273.       {
  274.          ++this.playCount;
  275.          dispatchEvent(new EffectEvent(EffectEvent.EFFECT_START,false,false,this));
  276.          if(Boolean(this.target) && this.target is IEventDispatcher)
  277.          {
  278.             this.target.dispatchEvent(new EffectEvent(EffectEvent.EFFECT_START,false,false,this));
  279.          }
  280.       }
  281.       
  282.       public function pause() : void
  283.       {
  284.          if(this.mx_internal::delayTimer && this.mx_internal::delayTimer.running && !isNaN(this.delayStartTime))
  285.          {
  286.             this.mx_internal::delayTimer.stop();
  287.             this.delayElapsedTime = getTimer() - this.delayStartTime;
  288.          }
  289.       }
  290.       
  291.       public function stop() : void
  292.       {
  293.          if(this.mx_internal::delayTimer)
  294.          {
  295.             this.mx_internal::delayTimer.reset();
  296.          }
  297.          this.mx_internal::stopRepeat = true;
  298.          dispatchEvent(new EffectEvent(EffectEvent.EFFECT_STOP,false,false,this));
  299.          if(Boolean(this.target) && this.target is IEventDispatcher)
  300.          {
  301.             this.target.dispatchEvent(new EffectEvent(EffectEvent.EFFECT_STOP,false,false,this));
  302.          }
  303.          this.finishEffect();
  304.       }
  305.       
  306.       public function resume() : void
  307.       {
  308.          if(this.mx_internal::delayTimer && !this.mx_internal::delayTimer.running && !isNaN(this.delayElapsedTime))
  309.          {
  310.             this.mx_internal::delayTimer.delay = !this.mx_internal::playReversed ? this.mx_internal::delayTimer.delay - this.delayElapsedTime : this.delayElapsedTime;
  311.             this.delayStartTime = getTimer();
  312.             this.mx_internal::delayTimer.start();
  313.          }
  314.       }
  315.       
  316.       public function reverse() : void
  317.       {
  318.          if(this.repeatCount > 0)
  319.          {
  320.             this.playCount = this.repeatCount - this.playCount + 1;
  321.          }
  322.       }
  323.       
  324.       public function end() : void
  325.       {
  326.          if(this.mx_internal::delayTimer)
  327.          {
  328.             this.mx_internal::delayTimer.reset();
  329.          }
  330.          this.mx_internal::stopRepeat = true;
  331.          this.finishEffect();
  332.       }
  333.       
  334.       public function finishEffect() : void
  335.       {
  336.          this.playCount = 0;
  337.          dispatchEvent(new EffectEvent(EffectEvent.EFFECT_END,false,false,this));
  338.          if(Boolean(this.target) && this.target is IEventDispatcher)
  339.          {
  340.             this.target.dispatchEvent(new EffectEvent(EffectEvent.EFFECT_END,false,false,this));
  341.          }
  342.          if(this.target is UIComponent)
  343.          {
  344.             UIComponent(this.target).effectFinished(this);
  345.          }
  346.          EffectManager.mx_internal::effectFinished(this);
  347.       }
  348.       
  349.       public function finishRepeat() : void
  350.       {
  351.          if(!this.mx_internal::stopRepeat && this.playCount != 0 && (this.playCount < this.repeatCount || this.repeatCount == 0))
  352.          {
  353.             if(this.repeatDelay > 0)
  354.             {
  355.                this.mx_internal::delayTimer = new Timer(this.repeatDelay,1);
  356.                this.delayStartTime = getTimer();
  357.                this.mx_internal::delayTimer.addEventListener(TimerEvent.TIMER,this.delayTimerHandler);
  358.                this.mx_internal::delayTimer.start();
  359.             }
  360.             else
  361.             {
  362.                this.play();
  363.             }
  364.          }
  365.          else
  366.          {
  367.             this.finishEffect();
  368.          }
  369.       }
  370.       
  371.       mx_internal function playWithNoDuration() : void
  372.       {
  373.          this.duration = 0;
  374.          this.repeatCount = 1;
  375.          this.repeatDelay = 0;
  376.          this.startDelay = 0;
  377.          this.startEffect();
  378.       }
  379.       
  380.       mx_internal function eventHandler(param1:Event) : void
  381.       {
  382.          if(param1.type == FlexEvent.SHOW && this.mx_internal::hideOnEffectEnd == true)
  383.          {
  384.             this.mx_internal::hideOnEffectEnd = false;
  385.             param1.target.removeEventListener(FlexEvent.SHOW,this.mx_internal::eventHandler);
  386.          }
  387.       }
  388.       
  389.       private function delayTimerHandler(param1:TimerEvent) : void
  390.       {
  391.          this.mx_internal::delayTimer.reset();
  392.          this.delayStartTime = NaN;
  393.          this.delayElapsedTime = NaN;
  394.          this.play();
  395.       }
  396.    }
  397. }
  398.  
  399.