I have an Object on stage, and on click I would like it to move to the center of the stage.
I know that I am supposed to use:
<s:move />
But I just don't know how!
I have an Object on stage, and on click I would like it to move to the center of the stage.
I know that I am supposed to use:
<s:move />
But I just don't know how!
这是一个示例应用程序,可以执行您想要的操作,您可以使用移动效果的属性。
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="init()">
<fx:Declarations>
<!-- Place non-visual elements (e.g., services, value objects) here -->
<s:Move id="moveEffect"></s:Move>
</fx:Declarations>
<s:BorderContainer id="box">
</s:BorderContainer>
<fx:Script>
<![CDATA[
import flash.events.MouseEvent;
private function init():void
{
box.setStyle("backgroundColor", "#ff0000");
box.width = 200;
box.height = 200;
box.addEventListener(MouseEvent.CLICK, onClick);
moveEffect.xTo = (width-box.width)/ 2;
moveEffect.yTo = (height-box.height) / 2;
}
private function onClick(e:MouseEvent):void
{
moveEffect.play([box]);
}
]]>
</fx:Script>
</s:Application>
希望有帮助。
而不是使用属性 x ......我使用了 mouseX 并且一切都按预期工作!