SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    movieclip 'stopped moving event' problem.

    Hey guys,

    I'm pretty stumped, so I thought I'd post my question here. I'm new to ActionScript, and frankly, I'm finding the way it handles time really confusing. But here's my problem. I've a button which, when clicked, makes a movieclip object move a certain distance across the screen at a certain pace. (Pretty revolutionary stuff, huh? ;-)

    My problem is, I can't seem to capture the moment after the movieclip has ceased moving. I need to run some code the moment it's reached it's destination - and I need it to run the code once.

    Here's the relevant aspects of my code:

    button code:

    on (release) {
    movieClipName.active = true;
    movieClipName.direction = "up";
    var why = movieClipName._y;
    movieClipName.destY = (why-40);
    movieClipName.destX = 0;
    }

    Movieclip code:

    onClipEvent(enterFrame) {
    if (active) {
    this.moveIt(direction, tag, destX, destY);
    }
    }

    (relevant) main timeline code:

    MovieClip.prototype.moveIt = function (direction, tag, destX, destY) {
    if (direction == "up") {
    if (this._y != destY) { this._y -= 4; }
    }
    }


    Given the above code, how do I 'capture' the moment when the movieclip has stopped moving? Like I said, I need to run some new code based on that event.

    Thanks guys. This is confusing stuff!

  2. #2
    Non-Member
    Join Date
    May 2003
    Location
    Mtl.
    Posts
    107
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    im not good in ActionScript... however... what about

    if movieClipName.Y=why-40{
    movieClipName.active = false;
    }

    this is out of my head i really dont know any ActionScript so it probably doesnt work but it gives an idea...

  3. #3
    ********* Ornithologist AtomicPenguin's Avatar
    Join Date
    May 2002
    Location
    Vancouver, BC
    Posts
    459
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    No go, unfortunately... any other ideas?

  4. #4
    SitePoint Wizard aaron.martone's Avatar
    Join Date
    Feb 2003
    Location
    Florida, USA
    Posts
    2,322
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Well, reaching a destination should be a simple cross check of current X and Y values.

    like

    startX= 30; startY = 20;
    destX=60; destY = 50;

    // move movieclip
    // check if destination is reached

    if (this._x == destX && this._y == destY) {
    movieClipName.active = false;
    }

    // check active variable status to see if destination is reached

    You may also want to start targeting your movie better. I do it as force of habit. Start everything with _root and go from there. Also, periodically trace key variables, and in design time you'll see if they contain the values you assume they should; cause if they don't, your functions and scripts may not perform in the manner you expect them to.

  5. #5
    Dumb PHP codin' cat
    Join Date
    Aug 2000
    Location
    San Diego, CA
    Posts
    5,460
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I I would move all the code to the timeline instead of using handlers placed directly on the instances for ease of maintenance.

    All of this in the main timeline or wherever the instances reside.
    Code:
    function moveUp() {
    if((this._y - 4) < this.destY) {
    this._y = this.destY;
    delete this.onEnterFrame;
    }
    else {
    this._y -= 4 ;
    }
    }
    myBtn.onRelease = function() {
    var why = movieClipName._y;
    movieClipName.destY = (why-40);
    movieClipName.destX = 0;
    movieClipName.onEnterFrame = moveUp;
    }
    That way your onEnterFrame event handler is dynamically assigned and then unassigned when the desired functionality has been performed.

    Again this assumes you have taken the on(release) and onClipEvent(enterFrame) handlers off the instances themselves.


Bookmarks

Posting Permissions

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