0

I have very little knowledge of ActionScript.

I have a movie clip. I want it to move along the x-axis when i press down on a button(button or movie clip) I do not know what code to use as it needs to be Action Script 2.

Is there a Tutorial or something that can accomplish this?

I have found a tutorial that moves the object around when you press a button. I am trying to get the same effect when you click down on a button:

http://www.kirupa.com/developer/actionscript/xymove.htm

Thank you for any help

UPDATE

The button is called btn and the object that moves is mctransparent I have managed the folowing:

onClipEvent (mouseDown) {
    _root.mctransparent.onEnterFrame = function() {
        if (_root._xmouse<_root.mctransparent._x) {
            _root.mctransparent._x -= 10;
        } else {
            _root.mctransparent._x += 10;
        }
    };
}
onClipEvent (mouseUp) {
    delete _root.mctransparent.onEnterFrame;
}

This is on the actions panel of the btn

But when you click on the object that must move it moves. I cannot get it so the object only moves when you click and hold on the btn.

4

2 回答 2

0

不是监听keyPress事件,而是监听pressorrelease事件。

所以你会有

btn_clickMe.onPress = function() {
    //whatever moving logic you are using
}

或者

btn_clickMe.onRelease = function() {
    //whatever moving logic you are using
}

或者,您可以删除btn_clickMe.并将代码放在btn_clickMe的操作面板中。

于 2011-12-08T11:46:53.593 回答
0

你可以有这样的东西(btnToClick_btn是按钮/电影剪辑的名称,objectToMove_mc是要移动的电影剪辑):

// this moves objectToMove_mc 10 pixels right any time you click the button
btnToClick_btn.onRelease=function(){
   objectToMove_mc._x+=10;
}

onRelease在单击后释放鼠标按钮时触发。onPress如果您希望在按下鼠标按钮时移动对象,则可以使用。

您应该将此代码放在时间轴的第一帧中,并且您应该在舞台上拥有 btnToClick_btn 和 objectToMove_mc。

于 2011-12-08T11:28:24.673 回答