Flex Move移动对象例子
Move 效果在指定的时间间隔内随时间更改组件的位置。您可以使用 xFrom
和 yFrom
值指定初始位置,使用 xTo
和 yTo
指定目标位置,或者使用 xBy
和 yBy
指定像素数目来移动组件。
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
import flash.events.MouseEvent;
import mx.containers.Canvas;
import mx.controls.Image;
import mx.effects.Move;
public var myimg:Image;
public function Sys(can:Canvas,img:Image):void{
can.addEventListener(MouseEvent.MOUSE_DOWN,Mousedown);//添加鼠标按下事件
this.myimg=img;
}
public function Mousedown(evevt:MouseEvent):void{
var move:Move=new Move();
move.target=myimg;//移动对象(控件)
move.duration = 500;//移动时间间隔0.5s
move.xTo=this.mouseX-20;
move.yTo=this.mouseY-20;
move.play();
}
import mx.containers.Canvas;
import mx.controls.Image;
import mx.effects.Move;
public var myimg:Image;
public function Sys(can:Canvas,img:Image):void{
can.addEventListener(MouseEvent.MOUSE_DOWN,Mousedown);//添加鼠标按下事件
this.myimg=img;
}
public function Mousedown(evevt:MouseEvent):void{
var move:Move=new Move();
move.target=myimg;//移动对象(控件)
move.duration = 500;//移动时间间隔0.5s
move.xTo=this.mouseX-20;
move.yTo=this.mouseY-20;
move.play();
}
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="Sys(can,img)">
<mx:Script source="mymove.as" />
<mx:Canvas id="can" width="100%" height="100%">
<mx:Image id="img" source="@Embed(source='n2.gif')"/>
</mx:Canvas>
</mx:Application>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
creationComplete="Sys(can,img)">
<mx:Script source="mymove.as" />
<mx:Canvas id="can" width="100%" height="100%">
<mx:Image id="img" source="@Embed(source='n2.gif')"/>
</mx:Canvas>
</mx:Application>