Flex4中的拖动技术
下面列一个最简单的例子,在Flex中,拖动原来如此简单
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
|
<?xml version= "1.0" encoding= "utf-8" ?> <s:Application xmlns:fx= "http://ns.adobe.com/mxml/2009" <s:layout> <s:BasicLayout/> </s:layout> <fx:Script> <![CDATA[ private function startMove(event:Event): void { Sprite(event.target).startDrag(); } private function stopMove(event:Event): void { Sprite(event.target).stopDrag(); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <mx:Button id= "btn" mouseDown= "startMove(event)" mouseUp= "stopMove(event)" label = "move" /> </s:Application> |
如果需要拖动的时候多个控件可以一起拖动,可以先用BorderContainer组件先把控件包含进来
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
<?xml version= "1.0" encoding= "utf-8" ?> <s:Application xmlns:fx= "http://ns.adobe.com/mxml/2009" <s:layout> <s:BasicLayout/> </s:layout> <fx:Script> <![CDATA[ private function startMove(event:Event): void { Sprite(bc).startDrag(); } private function stopMove(event:Event): void { Sprite(bc).stopDrag(); } ]]> </fx:Script> <fx:Declarations> <!-- 将非可视元素(例如服务、值对象)放在此处 --> </fx:Declarations> <s:BorderContainer id= "bc" x= "80" y= "92" width= "250" height= "200" mouseDown= "startMove(event)" mouseUp= "stopMove(event)" borderVisible= "true" > <s:Button x= "62" y= "62" label = "按钮" /> <s:Button x= "62" y= "124" label = "按钮" /> </s:BorderContainer> </s:Application> |
每一天都要行动,在前进中寻求卓越。