ActionScript 2 Moving an object

六月ゝ 毕业季﹏ 提交于 2019-12-20 07:37:41

问题


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.


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/8429910/actionscript-2-moving-an-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!