flex动态创建组件并放下
private function newHandler(event:MouseEvent):void{
var e:Element = new Element();
e.addEventListener(MouseEvent.CLICK,mouseClick);
Alert.show(e.width.toString());
}
<mx:Button x="185" y="10" label="New" click="newHandler(event)"/>
我要click后,这个Element能跟着mouse移动,然后mouse click了,就把element放下。
这个功能
有会的朋友指点下
[解决办法]
给你做了个实例,你可以参考下
<?xml version="1.0" encoding="utf-8"?><mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" width="100%" height="100%" mouseMove="mouserMoveHandler(event)" mouseDown="mouseDownHandler()" mouseUp="mouseUpHandler()" > <mx:Script> <![CDATA[ private var moveEnabled:Boolean = false; private function mouserMoveHandler(event:MouseEvent):void { if (moveEnabled) { var x:int = event.stageX; var y:int = event.stageY; canvas.x = x - canvas.width/2; canvas.y = y - canvas.height/2; } } private function mouseDownHandler():void { moveEnabled = true; } private function mouseUpHandler():void { moveEnabled = false; } ]]> </mx:Script> <mx:Canvas id="canvas" backgroundColor="red" width="100" height="100"/></mx:Application>
[解决办法]
帮顶下