Search code examples
createjsanimate-cc

How can I trigger a Button Rollover from a function call in Animate CC?


When you create a Button Symbol in Animate, it has the Up, Over, Down states. Is there a way to trigger that button Over state from a function?

something like:

button.onRollOver();

Thanks


Solution

  • The Stage handles mouse interaction, and determines what is interacted with. Once it has figured that out, it dispatches an event from that object (source):

    var evt = new createjs.MouseEvent(type, bubbles, false, o.x, o.y, nativeEvent, pointerId, pointerId === this._primaryPointerID || pointerId === -1, o.rawX, o.rawY, relatedTarget);
    target.dispatchEvent(evt);
    

    You should be able to replicate this fairly simply:

    var evt = new createjs.MouseEvent("rollover", false, x, y, null, 0, true, x, y, null);
    myBtn.dispatchEvent(evt);
    

    I am not sure exactly what this accomplishes though, since you could just fire the listener(s) that would otherwise get called yourself.

    Note also that there is a difference between "mouseover" and "rollover" events. Cheers,