startDrag 函数

startDrag(target:Object, [lock:Boolean, left:Number, top:Number, right:Number, bottom:Number]) : Void

使 target 影片剪辑在影片播放过程中可拖动。一次只能拖动一个影片剪辑。执行 startDrag() 操作后,影片剪辑将保持可拖动状态,直到用 stopDrag() 显式停止拖动为止,或直到对其它影片剪辑调用了 startDrag() 动作为止。

可用性:ActionScript 1.0、Flash Player 4

参数

target:Object ― 要拖动的影片剪辑的目标路径。

lock:Boolean [可选] ― 一个布尔值,指定可拖动影片剪辑是锁定到鼠标位置中央 (true),还是锁定到用户首次单击该影片剪辑的位置上 (false)。

left,top,right,bottom:Number [可选] ― 相对于该影片剪辑的父级的坐标的值,用以指定该影片剪辑的约束矩形。

示例

下面的示例在运行时创建影片剪辑 pic_mc,用户可以通过将 startDrag()stopDrag() 动作附加到该影片剪辑将它拖至任何位置。图像是使用 MovieClipLoader 类加载到 pic_mc 中的。

var pic_mcl:MovieClipLoader = new MovieClipLoader();
pic_mcl.loadClip("http://www.helpexamples.com/flash/images/image1.jpg",
 this.createEmptyMovieClip("pic_mc", this.getNextHighestDepth()));
var listenerObject:Object = new Object();
listenerObject.onLoadInit = function(target_mc) {
 target_mc.onPress = function() {
 startDrag(this);
 };
 target_mc.onRelease = function() {
 stopDrag();
 };
};
pic_mcl.addListener(listenerObject);

请参阅

stopDrag 函数, _droptarget(MovieClip._droptarget 属性), startDrag(MovieClip.startDrag 方法)