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.

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;

function onEnterFrame(e:Event):void
{
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. Thank you both, I got it!

Flashkit never lets me down

5. 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;
function nudge(e:Event):void{
mc.x += dx;
mc.y += dy;
if (mc.x == destination.x){
mc.removeEventListener(Event.ENTER_FRAME, nudge);
}
}

#### 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