Reputation: 21
I REALLY REALLY want to like CreateJS, but it is infuriating that basic things in AS3 are not working or are not capable. Here is a quick example:
I have a simple animation in a MovieClip, a circle moving from right to left. I have a
this.stop();
on the first frame and then a
this.stop();
on the last frame.
I drag that mc out to the main timeline, give it an instance of "main_mc" then create a function called init()
function init()
{
this.main_mc.play();
}
init();
This is the error I get:
Uncaught TypeError: Cannot read property 'play' of undefined
Any ideas?
Upvotes: 0
Views: 1698
Reputation: 275
@thatkidrich The problem is that "this" is scoped to the window and your 'main_mc' doesn't live on the window object. To reference your instance you will have to go through the 'exportRoot' object which will give you a reference to all your instance that you currently have on your FLA stage. I also wouldn't suggest coding your JS within the FLA, I would only use the exported JS for constructing assets. In your case I would control 'main_mc' via code outside within the HTML.
Example:
function init() {
canvas = document.getElementById("canvas");
exportRoot = new lib.Balltimeline();
stage = new createjs.Stage(canvas);
stage.addChild(exportRoot);
stage.update();
//This will give you a reference to your MC on stage.
var mc = exportRoot.main_mc;
mc.play();
createjs.Ticker.setFPS(lib.properties.fps);
createjs.Ticker.addEventListener("tick", stage);
}
Upvotes: 0