ActionScript 2 Moving an object

2019-03-04 20:19发布

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.

2条回答
forever°为你锁心
2楼-- · 2019-03-04 20:56

You could have something like this (btnToClick_btn is the name of a button/movieclip and objectToMove_mc is a MovieClip to move):

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

onRelease is fired when, after clicking, you release the mouse button. You can use onPress if you want the object move when you press the mouse button.

You should put this code in the first frame of the Timeline AND you should have on the stage btnToClick_btn and objectToMove_mc.

查看更多
beautiful°
3楼-- · 2019-03-04 21:01

Instead of listening for the keyPress event, listen for the press or release event.

so you'd have

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

or

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

Alternatively, you could remove the btn_clickMe. and put the code in the btn_clickMe's actions panel.

查看更多
登录 后发表回答