• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

832

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

Community Expert , 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 ca

...

Votes

Translate

Translate
Community Expert ,
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.

 

Votes

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

Votes

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 Expert ,
Nov 11, 2019 Nov 11, 2019

Copy link to clipboard

Copied

you're welcome.

Votes

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 

Votes

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 Expert ,
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.

Votes

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.

Votes

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 Expert ,
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.

Votes

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
LEGEND ,
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

Votes

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.

Votes

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
LEGEND ,
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);

 

 

Votes

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