12.1.在MXML和ActionScript里调用Effect

12.1.1. 问题
我想在应用程序里创建并调用一个效果实例。
12.1.2. 解决办法
如果要在MXML 里面定义一个效果,将Effect 标签加到你的组件的顶层标签内。若要在ActionScript 里面定义一个效果,导入正确的效果类,实例化之,分配一个UIComponent 作为其目标,并调用play 方法播放效果。
12.1.3. 讨论
Effect 类要求设置一个目标UIComponent。当在ActionScript 内实例化一个Effect,目标可以通过构造器传入Effect 内:
+展开
-ActionScript
var blur:Blur = new Blur(component);

The target can also be set once the Effect has been instantiated by using the target property of the Effect class. The target is the UIComponent that the Effect will affect when the play method of the Effect is called. When an Effect is defined in MXML, the target UIComponent must be assigned within a binding tag:
目标的设置也可以在Effect 实例化完成后通过设置Effect 类的target 属性来完成。所谓目标就是一个当调用Effect 的play 方法的时候会对其产生作用的UIComponent。当一个Effect定义在MXML 后,目标UIComponent 必须以绑定标签的形式进行分配:
+展开
-XML
<mx:Glow id="glowEffectduration="1000color="#ff0f0ftarget="{glowingTI}"/>

在下面的例子里,MXML 里面的Glow 效果将在点击按钮的时候进行实例化:
+展开
-XML
<mx:Button click="glowEffect.play()"/>

下一个例子里面,在applyBlur 方法里通过构造器将glowingTI 作为目标分配给Blur 效果。

在Effect 的相关属性成功设置后,调用play 方法。
+展开
-XML
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxmlwidth="400height="600">
<mx:Script>
<![CDATA[
import mx.effects.Blur;
private var blur:Blur;
private function applyBlur():void {
blur = new Blur(glowingTI);
blur.blurXFrom = 0;
blur.blurXTo = 20;//the amount of blur in pixels
blur.blurYFrom = 0;
blur.blurYTo = 20;//the amount of blur in pixels
blur.duration = 1000;
blur.play();
}

]]>
</mx:Script>
<!--the properties of the Glow effect set here are the color of the Glow and the length of time that the Glow will be displayed -->
<mx:Glow id="glowEffectduration="1000color="#ff0f0f"
target="{glowingTI}"/>

<mx:TextInput id="glowingTI"/>
<mx:Button click="applyBlur()toggle="trueid="glowToggle"
label="Play the BlurEffect"/>

<mx:Button click="glowEffect.play()label="Play the Glow
Effect
"/>

</mx:VBox>

加支付宝好友偷能量挖...


评论(0)网络
阅读(111)喜欢(0)flash/flex/fcs/AIR