User Guide
238 Creating Effects
When you define effects based on the TweenEffect class, you must override the
TweenEffectInstance.onTweenUpdate() method, and optionally override the
TweenEffectInstance.onTweenEnd() method.
This section describes how to create a tween effect. However, Flex supplies the
AnimateProperty class that you can use to create a tween effect for a single property of the
target component. For more information, see Chapter 17, “Using Behaviors,” in Flex 2
Developer’s Guide.
Example: Creating a tween effect
In this example, you create a tween effect that rotates a component in a circle. This example
implements a simplified version of the Rotate effect. The rotation is controlled by two
parameters that are passed to the effect:
angleFrom and angleTo:
package myEffects
{
// myEffects/Rotation.as
import mx.effects.TweenEffect;
import mx.effects.EffectInstance;
import mx.effects.IEffectInstance;
public class Rotation extends TweenEffect
{
// Define parameters for the effect.
public var angleFrom:Number = 0;
public var angleTo:Number = 360;
// Define constructor with optional argument.
public function Rotation(targetObj:* = null) {
super(targetObj);
instanceClass= RotationInstance;
}
// Override getAffectedProperties() method to return "rotation".
override public function getAffectedProperties():Array {
return ["rotation"];
}
// Override initInstance() method.
override protected function initInstance(inst:IEffectInstance):void
{
super.initInstance(inst);
RotationInstance(inst).angleFrom = angleFrom;
RotationInstance(inst).angleTo = angleTo;
}
}
}