杜鹏的小代码
中国 陕西 西安

导航

 

先写一个用于拖拽的管理类。代码如下

package com.util
{
import flash.events.MouseEvent;

import mx.core.Container;

public class DragManager
{
public static function moveObject(obj:Container):void
{
obj.addEventListener(MouseEvent.MOUSE_DOWN, objMouseDown);
obj.addEventListener(MouseEvent.MOUSE_UP, objMouseUp);
}

private static function objMouseDown(e:MouseEvent):void
{
e.currentTarget.startDrag();
}

private static function objMouseUp(e:MouseEvent):void
{
e.currentTarget.stopDrag();
}
}
}

接着在Flex页面上创建一个要拖拽的控件,然后调用这个上面的类中的moveObject方法就可以实现拖拽效果,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12"
initialize
="init()">
<mx:Panel x="41" y="28" width="250" height="200"
layout
="absolute" id="panel" title="拖拽">
</mx:Panel>
<mx:Script>
<![CDATA[
import com.util.DragManager;
private function init():void
{
DragManager.moveObject(this.panel);
}
]]>
</mx:Script>
</mx:Application>

 

posted on 2010-06-04 13:54  杜鹏  阅读(1417)  评论(0编辑  收藏  举报