Cmaxster
Cmaxster

Reputation: 1195

CreateJS JavasScript Frame Scripting in Animate CC

I used to be a Flash Developer, and I'm trying to understand the differences between ActionScript and the new CreateJS platform. I'm finding it difficult to find answers on Google so I figured I would ask here in hopes an expert can give me a solid explanation to build off of. Any help is very much appreciated.

Basically, I'm having difficulty understanding the complexities of timeline scope and how movie clips on the stage interact with each other in CreateJS. I'm also having trouble understanding how scope works between frames on the timeline.

In AS3 you could basically just drop a symbol on the stage and reference it on the main timeline like this:

if(ball_mc.aVariable == true) ball_mc.gotoAndPlay(2);

It seems, however, that in the new HTML5 Canvas Animate CC this no longer works. I get a lot of 'undefined'. I'm also finding that each frame is locked in scope. If I create a variable on frame 1 of ball_mc and then try to reference it on frame 2 I get an error unless I do something like this:

var aMovieClip = this.aMovieClip;

In ActionScript each nested timeline had it's own scope. If you created a variable on the first frame, that variable persisted across the entire timeline. I find it hard to believe that there is no easy way to extend the scope of a variable or function across a timeline. This is what made Flash a breeze when it came to adding interactivity on a timeline.

I tried to do the same thing with a function and I got an error like this:

createjs-2015.11.26.min.js:12 Uncaught TypeError: Cannot read property 'handleEvent' of undefined

I would like to understand how to have two movieclips on a timeline and have them interact with each other in a similar fashion as was possible in AS3:

MovieClip(parent).ball_mc.colour = 'red';

or..

this.addEventListener(MOUSE_EVENT.CLICK, callParentTimeline);
function callParentTimeline():void{
MovieClip(parent).gotoAndPlay(5);
}

etc. etc. etc.

this.parent isn't working for me.. and referencing a movieclip from the main timeline doesn't allow me to access it's frame variables along it's timeline.

I'm finding this confusing and frustrating because when I Google these issues, I find numerous articles that say such things as "Just say this.variable and it will work" or "just use parent.ball_mc to call the root", and I'm finding none of these suggestions seem to work.

Can any of you explain this to me?

Thank you!

Upvotes: 1

Views: 2438

Answers (1)

sebastian.derossi
sebastian.derossi

Reputation: 275

@Cmaxster You can always access your MovieClips that are on the stage via the exportRoot. For instance: If you have a ball with an instance name of myBall, it can be referenced like this var myBall = exportRoot.myBall;

If you wanted to post an FLA with more sepecific questions I can have a look :)

Upvotes: 2

Related Questions