Friday, February 4, 2005

UpdateAfterEvent

Easiest way to get this over is to imagine I am creating a custom cursor in Flash.

I have a class associated with a clip, in the class which extends MovieCliip have an onMouseMove event handler which updates the position of my clip and then call UpdateAfterEvent to make sure everything updates smoothly.

No problem it all works wonderfully!

Now a slight change in construction. Instead of associating my clip with the class I will make the class standalone, a plain old class object but I will pass it a reference to the clip it has to update.
Ok to make it work I need to make the class a MouseListener in order for the onMouseMove handler to get called.

Again no problem it all works!

Well... not exactly....

You see clearly the clips position is not being updated smoothly, there is a clear lag and its very jerky. Quite clearly UpdateAfterEvent is being ignored.

Now the Flash docs are a little confusing here.

Under UpdateAfterEvent it state that UpdateAfterEvent calls are ignored if they are not in an onClipEvent.

Under Mouse.onMouseMove however an example is given which is doing exactly as I am and calling UpdateAfterEvent from a Listener.

Now the 2 are not exactly mutually exclusive but it does leave room for doubt.

SO .......... should/does UpdateAfterEvent work when called from a Listener ?

2 comments:

  1. To answer myself...
    It doesn't work and the docs are wrong.
    Its was broken in at least v6 and continues to be broken despite what the docs say.

    ReplyDelete
  2. Hmm.. you're right, it does appear to be broken. A simple workaround, though not entirely efficient, is to set an interval that is just used for the update. I presume your cursor class looks something like this (this is as1 prototype style, just to paste the code in here).
    function Cursor() {
    Mouse.addListener(this);
    }
    Cursor.prototype.setCursor = function(mc) {
    this.mc = mc;
    }
    Cursor.prototype.onMouseMove = function() {
    this.mc._x = _xmouse;
    this.mc._y = _ymouse;
    var i = setInterval(function() {
    updateAfterEvent();
    clearInterval(i);
    }, 1);
    }
    var c = new Cursor();
    c.setCursor(cursor_mc);

    ReplyDelete