Animate - Built in functions?

Community Beginner ,
Nov 10, 2019 Nov 10, 2019

Copy link to clipboard

Copied

Hi, I'm converting an old Actionscript 1 Flash project to HTML5 Canvas (Javascript), and wondering if there are any built-in functions or global variables I can access, such as the Timeline's current frame number?


I have tried the following, but it is alerting as 'frameNumber=undefined'

 

 

/*
Get the frame number of current frame
*/
var frameNumber = _this.currentFrame;
alert("frameNumber="+this.frameNumber);

 

 

POST SCRIPT:

I changed the above to 

 

/*
Get the frame number of current frame
*/
var frameNumber = _this.currentFrame;
alert("frameNumber="+frameNumber);

 

 

and it worked.  I don't udnerstand the use of or scope of the "this".  Would someone be willing to explain it?

 

Also, do both these lines of code need to be inserted in every frame I want it displayed, or is there a global function way of accessing the framenumber, with simply (something like):

 

alert("frameNumber="+frameNumber);

 

 

Thanks,
Geoff

 

 

TOPICS
Code

Views

355

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct Answer

Adobe Community Professional , Nov 11, 2019 Nov 11, 2019
_this means nothing in canvas unless you define it.  eg, the snippets panel usually does something like var _this =  this; this refers to the entire timeline and is not frame dependent.  eg, this.var1 = "var1"; this.var1 is defined on every frame of the timeline that comtains the code. var var2 = "var2"; is defined only on the frame that contains that code.  ie, trying to reference var2 in a different frame will trigger and error. also, note there's a global script panel where you ...

Likes

Translate

Translate
Adobe Community Professional ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

_this means nothing in canvas unless you define it.  eg, the snippets panel usually does something like

var _this =  this;

 

this refers to the entire timeline and is not frame dependent.  eg,

 

this.var1 = "var1";

 

this.var1 is defined on every frame of the timeline that comtains the code.

 

var var2 = "var2";

 

is defined only on the frame that contains that code.  ie, trying to reference var2 in a different frame will trigger and error.

 

also, note there's a global script panel where you can use something like:

 

var var3 = "var3";

 

and it will be defined in every frame of every timeline in that canvas project.

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

Thanks for taking the time to explain that kglad... very helpful.

 

Kind regards,

Geoff

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

you're welcome.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

Ok, I have placed this in my Global Script panel:

var frameNumber = this.currentFrame;

 and on frame 1 of Timeline added this code:

alert("frameNumber="+frameNumber);

But it is still undefined.  I have also tried the above with and without the ".this".

What am I doing wrong?

 

Thanks,
Geoff 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

attach a screenshot showing your global panel and the code.

 

p.s. that will always show the currentFrame (eg, 0) when the code executes.  ie, it won't update as the frames change.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

Sure, here:

Global:

In Global Script PanelIn Global Script Panel

 

Frame 1:On Frame 1 of TimelineOn Frame 1 of Timeline

 

Thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 12, 2019 Nov 12, 2019

Copy link to clipboard

Copied

oops, it's a global script, not a frame script so currentFrame is meaningless (ie, isn't defined) in the global panel.  further, "this" references the main window object, not a movieclip/timeline.

 

use something that doesn't poll the timeline or frame in the global panel.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

Of course there are built-in functions and variables. Wouldn't be much point to having a scripting language if there weren't, would there?

 

https://createjs.com/docs/easeljs/modules/EaselJS.html

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

Ok thanks.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Adobe Community Professional ,
Nov 12, 2019 Nov 12, 2019

Copy link to clipboard

Copied

LATEST

> is there a global function way of accessing the framenumber

 

There is no "the" frame number for "the" timeline. The root timeline and every single movie clip on the stage all have their own timelines and frame numbers. If you want a frame number, you have to specify which timeline you want it from.

 

That being said, if you want to globally access the root frame number, that's accessible from the automatically-created global alias to the root timeline, exportRoot.

 

alert(exportRoot.currentFrame);

 

 

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines