1
我正在爲移動應用程序使用Flash Builder 4.6。我需要將圖像拖放到容器中的其他圖像上,並且必須通過從其他視圖獲取值來動態定位可拖動圖像。我是flex的移動應用程序開發新手。指導我一些教程或例子。將圖片拖動到圖片上並在柔性手機中動態定位
我正在爲移動應用程序使用Flash Builder 4.6。我需要將圖像拖放到容器中的其他圖像上,並且必須通過從其他視圖獲取值來動態定位可拖動圖像。我是flex的移動應用程序開發新手。指導我一些教程或例子。將圖片拖動到圖片上並在柔性手機中動態定位
在這裏,讓你開始...可拖動紅色圓圈
myApp.mxml在:
<?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"
xmlns:comps="*">
<comps:MyCircle width="100%" height="100%"/>
</s:Application>
MyCircle.mxml:
<?xml version="1.0" encoding="utf-8"?>
<mx:UIComponent
xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import flash.filters.*;
public static const SHADOW:Array = [ new DropShadowFilter(10, 80, 0x000000, 0.5, 32, 32, 1, 1, false, false, false) ];
private var dX:Number, dY:Number;
private var circle:Shape = new Shape();
override protected function createChildren():void {
super.createChildren();
circle.graphics.beginFill(0xFF0000);
circle.graphics.drawCircle(0, 0, 20);
addChild(circle);
addEventListener(MouseEvent.MOUSE_DOWN, handleDown);
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
circle.x = unscaledWidth/2;
circle.y = unscaledHeight/2;
}
private function handleDown(event:MouseEvent):void {
dX = circle.x - stage.mouseX;
dY = circle.y - stage.mouseY;
circle.scaleX = circle.scaleY = 1.5;
circle.filters = SHADOW;
stage.addEventListener(MouseEvent.MOUSE_MOVE, handleDrag);
stage.addEventListener(MouseEvent.MOUSE_UP, handleUp);
}
private function handleDrag(event:MouseEvent):void {
circle.x = stage.mouseX + dX;
circle.y = stage.mouseY + dY;
event.updateAfterEvent();
}
private function handleUp(event:MouseEvent):void {
circle.filters = null;
circle.scaleX = circle.scaleY = 1;
stage.removeEventListener(MouseEvent.MOUSE_MOVE, handleDrag);
stage.removeEventListener(MouseEvent.MOUSE_UP, handleUp);
}
]]>
</fx:Script>
</mx:UIComponent>