我是AS3的新手,并试图创建一个可拖动的元素。但是,我一直收到错误1061,我不知道为什么,因为我很确定我没有任何拼写错误或类似错误。有人可以告诉我我做错了吗?
这是我的代码:
package {
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;
public class Script extends MovieClip{
public var value:Number;
private var max:Number;
private var min:Number;
public function Draggable(){
min = erhu_mc.y;
max = erhu_mc.height - Erhu_H3_btn.height;
Erhu_H3_btn.addEventListener(MouseEvent.MOUSE_DOWN, dragHandle);
}
function dragHandle(event:MouseEvent):void {
Erhu_H3_btn.startDrag(new Rectangle, false,(0,min,0,max));
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
}
function stopDragging(event:MouseEvent):void {
Erhu_H3_btn.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
}
}
}
答案 0 :(得分:0)
您当前的课程有2个问题。
Erhu_H3_btn.startDrag(new Rectangle, false,(0,min,0,max));
需要:Erhu_H3_btn.startDrag(false,new Rectangle(0,min,0,max));
您无法直接从类的时间轴中引用对象。[ref]您需要传递对象的引用或对舞台的引用。例如,以下内容返回null:
import flash.display.*;
public class Script extends MovieClip {
public function Script() {
trace(stage);
}
我复制并模式化你的代码,使其适用于框架。:
import flash.display.*;
import flash.events.*;
import flash.geom.Rectangle;
var value:Number;
var max:Number;
var min:Number;
Draggable();
function Draggable(){
min = Erhu_H3_btn.y;
max = Erhu_H3_btn.y += 100;
Erhu_H3_btn.addEventListener(MouseEvent.MOUSE_DOWN, dragHandle);
}
function dragHandle(event:MouseEvent):void {
Erhu_H3_btn.startDrag(false,new Rectangle(0,min,0,max));
stage.addEventListener(MouseEvent.MOUSE_UP, stopDragging);
}
function stopDragging(event:MouseEvent):void {
Erhu_H3_btn.stopDrag();
stage.removeEventListener(MouseEvent.MOUSE_UP, stopDragging);
}
希望这有帮助。