-
This is a very simple question. I have one movie clip with instance name 'Dude' and I have one button. When I press the button, I want 'Dude' to move it's _x position 25 pixels to the right. But I want the viewers to see it move at a constant speed. I don't want it to just pop up towards the right. I want it to move there. What's the code to do this? Will I need a extra blank movie clip to do this?
BB
-
you could have a loop that moves it 1 pixel at a time, till it reaches 25
code:
___________________________________
function moveMC(this)
{
distance = 25;
for (i = 0; i <= distance; i++)
{
this._x += 1;
}
}
then on your button you can have
on (release)
{
_root.moveMC(dude);
}
___________________________________
I'm not quite sure if flash will execute the loop and then place the mc 25 pixels to the right....or if it will move 1 pixel while the loop is being executed....let me know if this doesn't work
hope that helps
-
graphicguru,
Actually, a "for" loop will execute pretty much instantaneously, so this script will cause the MC to move immediately to 25 pixels to the right.
You could try something like this on your dude movie clip:
onClipEvent(enterFrame) {
if(this._x < dudeMove) {
this._x = this._x + 1
}
onClipEvent(load) {
dudeMove = this._x
}
And then on your button:
on(release) {
Dude.dudeMove=Dude.dudeMove + 25
}
-
philter
I totally realized it after I submitted!!
I totally for got that a loop doesn't update or refresh until after the loop has completed.
nice post... you hit it on the head
-
-
Thanks guys, I will give it a try.
BB
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|