A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Newbie actionscripter - Moving MC

  1. #1
    Member
    Join Date
    Jan 2003
    Posts
    85

    Newbie actionscripter - Moving MC

    Im trying to move 2 MC's with actionscript.

    First MC name=test (move from y=28 to y=128)
    onClipEvent (load) {
    _root.x = 361.5;//change this to where it goes to.
    _root.y = 128;//change this to where it goes to.
    speed = 10;//change the speed.
    }
    onClipEvent (enterFrame) {
    x = (_root.x-this._x)/speed;
    y = (_root.y-this._y)/speed;
    this._x += x;
    this._y += y;
    }

    Next MC name=test2 (move from y=327 to y=227) - moving at the same time as first MC

    onClipEvent (load) {
    _root.x = 361.5;//change this to where it goes to.
    _root.y = 227;//change this to where it goes to.
    speed = 10;//change the speed.
    }
    onClipEvent (enterFrame) {
    x = (_root.x-this._x)/speed;
    y = (_root.y-this._y)/speed;
    this._x += x;
    this._y += y;
    }

    This doesnt work - well the first MC is fine but the second one moves way to high

  2. #2
    Senior Member tigersbite's Avatar
    Join Date
    Apr 2002
    Posts
    314
    I'm not seeing the problem. Your code works fine for me.

  3. #3
    Registered User nunomira's Avatar
    Join Date
    May 2002
    Location
    portugal
    Posts
    7,003
    you're defining the same variables twice (which doesn't make sense) and one of them has two different values, so, the last which is read by the flash player will prevail

    so, instead of sending the variables to the _root, you can define them in each of the mcs:
    Code:
    onClipEvent (load) {
    x = 361.5;//change this to where it goes to.
    y = 128;//change this to where it goes to.
    speed = 10;//change the speed.
    }
    onClipEvent (enterFrame) {
    z = (x-this._x)/speed;
    w = (y-this._y)/speed;
    this._x += z;
    this._y += w;
    }
    Code:
    onClipEvent (load) {
    x = 361.5;//change this to where it goes to.
    y = 227;//change this to where it goes to.
    speed = 10;//change the speed.
    }
    onClipEvent (enterFrame) {
    z = (x-this._x)/speed;
    w = (y-this._y)/speed;
    this._x += z;
    this._y += w;
    }
    you also defined speed in the movieClip
    if you want to define all the variables in the _root, you'll have to use diferent names for different values.

  4. #4
    Member
    Join Date
    Jan 2003
    Posts
    85
    Thanks nunomira

    It works - and I understand AS a little better

    Another thing.

    These movements are easing out - how would I make it ease in instead.
    Last edited by The Krook; 02-13-2003 at 11:52 AM.

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