A Flash Developer Resource Site

# Thread: Moving movie clip across stage?

1. ## Moving movie clip across stage?

Hey,

How would I move a movie clip from a (non-specified) point, to a designated destination (in coordinates)?

For example, move a movie clip named "Guy" to coordinates X=100, Y=100.

Thanks in advance!

2. ## Whoops...

I read that again, and realized I forgot to mention something...

I need it to move progressively, not instantly.

Like, scoot across the screen, instead of just appearing there.

Thanks!

3. You can have velocity variables like vX and vY. Probably inside a timer event or enter frame, have your movie clip (mc) coordinates updated. Something like this:
Actionscript Code:
`var vX:uint = 2;var vY:uint = 3;addEventListener(Event.ENTER_FRAME, onEnterFrame);function onEnterFrame(e:Event):void{   //your movie clip's position    mc.x += vX;    mc.y += vY;   //stop the movement when your movie clip reaches the position   if (mc.x >= 100)   {       vX = 0;   }   if (mc.y >= 100)   {       vY = 0   }}`

4. I'd use a tweening engine like TweenLite, where you'd do something like:
Code:
`TweenLite.to(mc, 1, {x:100, y:100});`
But you can do this yourself, too.
Code:
```var destination:Point = new Point(100, 100);
var steps:int = 100; //how many frames to get there.
var dx:Number = (destination.x - mc.x) / steps;
var dy:Number = (destination.y - mc.y) / steps;
mc.addEventListener(Event.ENTER_FRAME, nudge);
function nudge(e:Event):void{
mc.x += dx;
mc.y += dy;
if (mc.x == destination.x){
mc.removeEventListener(Event.ENTER_FRAME, nudge);
}
}```

5. Thank you both, I got it!

Flashkit never lets me down

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•

 » Home » Movies » Tutorials » Submissions » Board » Links » Reviews » Feedback » Gallery » Fonts » The Lounge » Sound Loops » Sound FX » About FK » Sitemap

Click Here to Expand Forum to Full Width