制作简单按钮的ActionScript 3.0代码是什么?

时间:2011-01-27 01:01:10

标签: flash actionscript-3

使用actionscript 3.0代码创建一个非常简单的按钮,将用户带到下一帧?如果我在ActionScript 2.0中记得正确,那就是: instance_name.onPress = function(){ gotoAndStop(2) } 或类似的东西。但是,ActionScript 3.0不是这种情况。有人可以告诉我吗?谢谢!

4 个答案:

答案 0 :(得分:3)

ActionScript 3使用基于事件的系统,因此要在用户单击DisplayObject时收到通知,您需要侦听点击MouseEvent

myDisplayObject.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
  event.target.gotoAndStop(2);
}

答案 1 :(得分:1)

这里的答案具有正确的功能功能,但也考虑用户体验,您可能想要分配这些值:

myDisplayObject.buttonMode = true //use the "hand" cursor on mouseover
myDisplayObject.mouseChildren = false //stops the children of the button firing the event, helpful especially when having text lables etc.

答案 2 :(得分:0)

function eventResponse(evt:MouseEvent):void {gotoAndStop(2);}

yourButton.addEventListener(MouseEvent.MOUSE_UP,eventResponse);

答案 3 :(得分:0)

private var按钮:Sprite = new Sprite();

      public function ButtonInteractivity() 
        button.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
        addChild(button);
      }

      private function mouseDownHandler(event:MouseEvent):void {
        your code!!
      }