Macromedia flex 2 Manual
240
Creating Effects
In this example, Tween object invokes the
onTweenUpdate()
callback method on a regular
interval, passing it values between
angleFrom
and
angleTo
. At the end of the effect, the
Tween object calls the
onTweenUpdate()
callback method with a value of
angleTo
. By
invoking the
onTweenUpdate()
callback method at regular intervals throughout the duration
of the effect, the target component displays a smooth animation as it rotates.
You use your new effect in an MXML application, as the following example shows:
<?xml version="1.0"?>
<!-- effects/MainRotation.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myEffects.*">
<!-- effects/MainRotation.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myEffects.*">
<MyComp:Rotation id="Rotate90"
angleFrom="0" angleTo="360"
duration="1000"/>
<mx:Image source="@Embed(source='../assets/myImage.jpg')"
mouseDownEffect="{Rotate90}"/>
</mx:Application>
angleFrom="0" angleTo="360"
duration="1000"/>
<mx:Image source="@Embed(source='../assets/myImage.jpg')"
mouseDownEffect="{Rotate90}"/>
</mx:Application>
In this example, you use the effect to rotate an image when the user clicks it.
Writing an effect for a transition
Transitions define how a change of view state appears on the screen. You define a transition by
using a combination of the Flex effect classes. For more information on transitions, see
Chapter 28, “Using Transitions,” in Flex 2 Developer’s Guide.
using a combination of the Flex effect classes. For more information on transitions, see
Chapter 28, “Using Transitions,” in Flex 2 Developer’s Guide.
You can define your own custom effects for use in transitions. To do so, you have to account
for the effect being used in a transition when you override the
for the effect being used in a transition when you override the
EffectInstance.play()
method. The
EffectInstance.play()
method must be able to determine default values for
effect properties when the effect is used in a transition.
Defining the default values for a transition effect
Like any effect, an effect in a transition has properties that you use to configure it. For
example, most effects have properties that define starting and ending information for the
target component, such as the
example, most effects have properties that define starting and ending information for the
target component, such as the
xFrom
,
yFrom
,
xTo
, and
yTo
properties of the
Move
effect.