My first AS thread , I hope it's useful...
What it does basicly is make your character or whatever go to the place you last clicked. Useful for Point 'n Click games.
open the actionscript window of the frame you want to be moved in...
Put your character in it and give it the instance name 'char' ( without '')
Give THE FRAME ( not the character) following code :
clickedx = _root.char._x
//the initial clickedx is the x-position of your character
clickedy = _root.char._y
//the initial clickedy is the y-position of your character
clicking = false;
//this is just to make sure you can only define the clickedx and y once while you're mouse- //button is down
onMouseDown = function () {
if (clicking == false) {
clicking = true;
clickedx = _xmouse;
clickedy = _ymouse;
//defines position of clicked X and Y
}
};
onMouseUp = function () {
clicking = false;
};
Now Give the character 'char' the following code :
onClipEvent(load){
ms = 10
//defines the moving speed
}
onClipEvent (enterFrame) {
// Tells the character to go to the clicked x-position
if (_root.clickedx>_x) {
_x += ms;
}
}
onClipEvent (enterFrame) {
if (_root.clickedx<_x) {
_x -= ms;
}
}
onClipEvent (enterFrame) {
// Tells the character to go to the clicked y-position
if (_root.clickedy>_y) {
_y += ms;
}
}
onClipEvent (enterFrame) {
if (_root.clickedy<_y) {
_y -= ms;
}
}
Test it out , This Should work...