View Full Version : moving a mc only with actions
webzoogirl
11-22-2001, 09:02 AM
hi all
I'm learning how to use as for moving mc. I've used 'motion using action script' tutorial to move a mc to a x and y value (i just changed some values) but now I'd want my mc to move on the stage between two coordinates: x=20 to x=40 and Y=21 to y=53. So my mc must start with x=20 and y=21, move to x=40 and y=53, and when it reaches this coordinates, I want to put it to the original coordinates (x=20 and y=21) and redo the same movement (to x=40 and y=53) again. How can I do it? please help me, I'm a newbie with as ;-)
thanx
Ricod
11-22-2001, 09:57 AM
Well, you're going to need variables now. Have u read the variables tutorial yet ? Basically u declare one like this :
_root:variableName = someValue;
So, u could say something like :
_root: originalX = 20;
_root: originalY = 21;
_root:borderX = 40;
_root:borderY = 53;
// PLZ note, there's no space between : and O but was nessecary to prevent smilies)
Next, use if statements to check if u have reached your border :
var currentX = _root.mcThatsMoving._x;
var currentY = _root.mcThatsMoving._y;
// var is a local variable. It's removed from yer memory after its not needed anymore
if (_root.mcThatsMoving._x <= _root:borderX) {
_root.mcThatsMoving._x = _root.mcThatsMoving._x + 2;
} else {
_root.mcThatsMoving._x = _root: originalX;
}
Do the same for the Y, and you're good to go. Do note that its calculted from the registration point (the black cross)
Good luck !
webzoogirl
11-22-2001, 10:32 AM
now it works :-)))
I wrote the > or = condition in separate scripts, that's why it didn't work...
thx very muuuuuuuuuuuuuch!
:-D
Ricod
11-22-2001, 10:36 AM
well (blush blush !) ...
welcome to the forum, webzoogirl !
webzoogirl
11-22-2001, 12:45 PM
he he
here I am again! just one thing...
what is the difference between these two ways of setting variables:
_root.namevariable = 10 I've always used this
and
_root:namevariable = 10 this is that one you gave me
???
what is exactly ':' ?
have a nice day ;-)
Ricod
11-22-2001, 12:53 PM
ehm ... I'm not really sure myself. They both work. But : only works for variables, thus u now its a variable. I believe it depends on yer notation. Using the tidy-code way it makes no difference, but old-style it does (? <- like I said, not sure).:rolleyes:
Ah ... just one ? :p Then u too.
evilregis
11-22-2001, 01:29 PM
me thinks it's a matter of taste or coding style as well.
i too use the dot to declare variables. i might consider the colon in the future tho to make it more clear that a variable is being declared as opposed to modified. i could see it's benefit.
also, when i declare a local variable, i do not use 'var'... does THAT make any difference? it seems from my working with it that it does not, and again, i am thinking it's a matter of coding preference... but i would just like to make sure.
.:er:.
Ricod
11-22-2001, 02:45 PM
Like I said. local variables using var are removed from your memory after the code's done. The normal ones remain there.
fpanko
11-29-2001, 10:17 PM
I have a ton of free scripts that move or movies acording to variables and different math formulas. If you want to try any other ways of doing it, I have downloadables at www.geckoarts.com
hope this helps, frank
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.