" />

New events in EaselJS: added, removed, and change

A few new events have been added to EaselJS that provide additional functionality to developers.

DisplayObjects now dispatch non-bubbling “added” and “removed” events when they change parents. This is going to be familiar to anyone coming from Flash. A common use case is to listen for these events, and check the stage property to determine if the child has just been added to the stage (and is therefore visible). Note that stage is now a handy getter on any DisplayObject, instead of the deprecated `getStage` method.

var sprite = new createjs.Sprite(spriteData);
sprite.on(“added”, function(event) {
    if (event.target.stage != null) {
        // Added to stage
    }
});

Additionally, Sprites now dispatch a “change” event any time the displayed frame changes. This functionality already exists on any Tween in TweenJS, and is a natural addition to the Sprite class.

sprite.on(“change”, function(event) {
    // The sprite frame changed.
});

5 thoughts on New events in EaselJS: added, removed, and change

  1. I am not getting the object’s stage property right away – have to setTimeout in the added event listener. For instance, event.target.stage is not working. Is it working for you? Tried in latest Firefox and Chrome using the posted 2014 build.

Leave a Reply

Your email address will not be published. Required fields are marked *

© Copyright 2017