PHP User Warning: fetch_template() calls should be replaced by the vB_Template class. Template name: bbcode_highlight in ..../includes/functions.php on line 4197
Moving movie clip across stage?
A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Moving movie clip across stage?

  1. #1
    Junior Member
    Join Date
    May 2010
    Posts
    23

    Post 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. #2
    Junior Member
    Join Date
    May 2010
    Posts
    23

    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. #3
    Senior Member
    Join Date
    Dec 2010
    Posts
    121
    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
       }
    }
    Last edited by flashmed; 08-05-2011 at 09:01 AM.

  4. #4
    Will moderate for beer
    Join Date
    Apr 2007
    Location
    Austin, TX
    Posts
    6,801
    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. #5
    Junior Member
    Join Date
    May 2010
    Posts
    23
    Thank you both, I got it!

    Flashkit never lets me down

Tags for this Thread

Posting Permissions

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




Click Here to Expand Forum to Full Width

HTML5 Development Center