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);
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):
_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.
Thanks for taking the time to explain that kglad... very helpful.
Ok, I have placed this in my Global Script panel:
var frameNumber = this.currentFrame;
and on frame 1 of Timeline added this code:
But it is still undefined. I have also tried the above with and without the ".this".
What am I doing wrong?
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.
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.
> 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.