View Full Version : movement with actionscript in flash
mikeyb
March 26th, 2003, 04:25 PM
Ok, I recently got intrested in flash and now want to increase my flash ability with actionscript,
I have Flash MX and am wondering how with action script i can move a symbol or movieclip when clicking on a button with the use of actionscript. I want to be able to to move a symbol or movieclip to an exact location and with some animation like a motion tween but with the use of actionscript.
Can anyone shed any light on the subject , I really need help and am looking for any suggestions.
liam
March 26th, 2003, 11:18 PM
mikey,
check out this tutorial on Kirupa to find out more:
http://www.kirupa.com/developer/mx/ASmovement.htm
if that doesn't help, post your questions on here and i'll be sure to answer :)
mikeyb
March 27th, 2003, 12:34 PM
yes that was helpful but how can i make the symbol or movieclip stop and start at a specific location,
such as starting at x 50 y 50 and finishing at x 50 y 100 ?
please reply and
thankyou
morse
March 27th, 2003, 12:49 PM
put it at x50 and y50, then
onClipEvent(enterFrame) {
speed = 5;
if(this._y<100){
this._y += speed;
}
}
untested, see if that works
mikeyb
March 27th, 2003, 12:56 PM
morse u rule !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
if i need any more help ur the one to try
thanx
mike
morse
March 27th, 2003, 01:02 PM
:) Thanks man. I'm nothing compaired to most of the people on this site.
Anyway, if you have any questions, feel free to PM me, or email me: himself@morsedesigns.com
mikeyb
March 27th, 2003, 01:02 PM
ooh
one more question how can i make it start moving from where it was so it can move up and down with the use of a button? and when u click another button it starts from where it was and goes to a new location
thanx for your help
mike
morse
March 27th, 2003, 01:07 PM
On the stage make two buttons. One above the other. Call the top one (using instance names) "MCup" and the bottom one "MCdown" (both without quotes). On the stage name the thing you want to move (using instance names) "myMC".
//Code for the top button - MCup
on(release){
_root.myMC._y+=5
}
//Code for the bottom button - MCdown
on(release){
_root.myMC._y-=5
}
untested, see if it works
mikeyb
March 27th, 2003, 04:23 PM
ok thAT WAS ALMOST WHAT I WANTED BUTi wanted to be able to move the button continuously from point to point with only one click of the button and it move to a specific location like with the
previous example instead of stopping every 5 pixels
is this possible
thanx mike
morse
March 27th, 2003, 05:35 PM
I'v been meaning to try this... Here's my chance :)
Try this. In the first frame of the timeline put this:
MovieClip.prototype.move = function() {
speed = 25;
endX = 200;//Final X position you want
endY = 200;//Final Y Position you want
this._x += (endX-this._x)/speed;
this._y += (endY-this._y)/speed;
};
on the movie clip that is to move (myMC) put this:
onClipEvent(enterFrame){
move()
}
morse
March 27th, 2003, 11:55 PM
The cool thing is that you could change the endx and endy values to variables and then change them when a button is pushed, and the thing will automatically move.
morse
March 28th, 2003, 12:14 AM
I think.
mikeyb
March 29th, 2003, 01:58 PM
HOW CAN I CHANGE THE endy and endx to VARIABLES and make them change when a button is pressed sorry im a bit new at this your help is much aprecated
thanx
mike
darthmahon
December 7th, 2004, 09:12 AM
Do it like this:
MovieClip.prototype.move = function(endX, endY, speed) {
this._x += (endX-this._x)/speed;
this._y += (endY-this._y)/speed;
};
And in your movieclip put this:
onClipEvent(enterFrame){
move(200, 200, 25)
}
Notice how the following two lines match up??
MovieClip.prototype.move = function(endX, endY, speed)
move(200, 300, 25)
So 200 is your "endX" value, 300 is your "endY" value and 25 is your "speed"...hope that makes sense.
Cheers,
Chris
tomasofsweden
February 26th, 2008, 08:10 AM
Hi all im new to this forum and new to actionscript as well. Im looking for something very similar to this thread. i need a background img to move animated to a certain x y by the click of a meny item. When clicking another meny item i need the background img to start moving from its currant location to another x y using the same amount of time. And so on and so forth with other meny items... is this possible?
Regards Tomas.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.