Warning: Use of undefined constant auto - assumed 'auto' (this will throw an Error in a future version of PHP) in /nfs/c04/h02/mnt/66465/domains/blog.createjs.com/html/wp-content/themes/createjs-blog/functions.php on line 71
Getter/Setters in CreateJS - CreateJS Blog

Getter/Setters in CreateJS

One of the things we have always wanted to add to CreateJS was more support for getter/setter properties. This has some limitations for libraries that need to support older browsers, so this was bumped to our “nice to have” list until recently.

EaselJS has the benefit of requiring Canvas support – which means that it will only be used in modern browsers, which all have consistent support for getter/setter properties. This revision has (finally) added a bunch of useful functionality to properties that already existed, and some of the methods (such as “MovieClip.getCurrentLabel()”) have been changed to property getters.

All getter/setter properties are backed by public or private methods, and browsers that do not support getter/setters simply do not initialize them (which causes a run-time error). If you are building apps for the modern web (IE9+), then the new get/set properties are much easier to work with.

Here is a list of the available getter/setters we are planning for launch. EaselJS and SoundJS already have implementations ready for testing!


EaselJS [added in 0.8.0]
MouseEvent.localX (readonly)
MouseEvent.localY (readonly)
MouseEvent.isTouch (readonly)
Container.numChildren (readonly)
DisplayObject.stage (readonly)
Graphics.instructions (readonly)
MovieClip.labels (readonly)
MovieClip.currentLabel (readonly)
SpriteSheet.animations (readonly)
SpriteStage.isWebGL (readonly)

SoundJS [added in 0.6.0]

We plan on adding getter setters to TweenJS/PreloadJS shortly as well.

2 thoughts on Getter/Setters in CreateJS

Leave a Reply

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

© Copyright 2020