首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 媒体动画 > flex >

flex动态创建组件并放下,该如何解决

2012-02-29 
flex动态创建组件并放下private function newHandler(event:MouseEvent):void{var e:Element new Elemen

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 code
<?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>
[解决办法]
帮顶下

热点排行