Files
2013-04-25 13:56:18 -07:00

68 lines
2.5 KiB
ActionScript

// =================================================================================================
//
// Starling Framework
// Copyright 2011 Gamua OG. All Rights Reserved.
//
// This program is free software. You can redistribute and/or modify it
// in accordance with the terms of the accompanying license agreement.
//
// =================================================================================================
package starling.animation
{
/** A DelayedCall allows you to execute a method after a certain time has passed. Since it
* implements the IAnimatable interface, it can be added to a juggler. In most cases, you
* do not have to use this class directly; the juggler class contains a method to delay
* calls directly.
*
* @see Juggler
*/
public class DelayedCall implements IAnimatable
{
private var mCurrentTime:Number = 0;
private var mTotalTime:Number;
private var mCall:Function;
private var mArgs:Array;
private var mRepeatCount:int = 1;
/** Creates a delayed call. */
public function DelayedCall(call:Function, delay:Number, args:Array=null)
{
mCall = call;
mTotalTime = Math.max(delay, 0.0001);
mArgs = args;
}
/** @inheritDoc */
public function advanceTime(time:Number):void
{
var previousTime:Number = mCurrentTime;
mCurrentTime = Math.min(mTotalTime, mCurrentTime + time);
if (previousTime < mTotalTime && mCurrentTime >= mTotalTime)
{
mCall.apply(null, mArgs);
if (mRepeatCount > 1)
{
mRepeatCount -= 1;
mCurrentTime = 0;
advanceTime((previousTime + time) - mTotalTime);
}
}
}
/** @inheritDoc */
public function get isComplete():Boolean { return mCurrentTime >= mTotalTime; }
/** The time for which calls will be delayed (in seconds). */
public function get totalTime():Number { return mTotalTime; }
/** The time that has already passed (in seconds). */
public function get currentTime():Number { return mCurrentTime; }
/** The number of times the call will be repeated. */
public function get repeatCount():int { return mRepeatCount; }
public function set repeatCount(value:int):void { mRepeatCount = value; }
}
}