Copy link to clipboard
Copied
Hi,
I have a newbie question.
I want to define and execute a function and apply that code it to a frame in the timeline.
Previously, I've used the same function on a button click event:
this.button_name.on('click', function ()
{
var randomframe = Math.floor(Math.random() * _this.movieclip.totalFrames);
_this.movieclip.gotoAndStop(randomframe);
});
How do I modify the above so that it executes upon entering a frame instead of a click event?
var randomframe = Math.floor(Math.random() * _this.movieclip.totalFrames);
_this.movieclip.gotoAndStop(randomframe);
will work. but if you really want to execute a function, you can do it more verbosely with:
gotoF();
function gotoF(){
var randomframe = Math.floor(Math.random() * _this.movieclip.totalFrames);
_this.movieclip.gotoAndStop(randomframe);
}
Copy link to clipboard
Copied
var randomframe = Math.floor(Math.random() * _this.movieclip.totalFrames);
_this.movieclip.gotoAndStop(randomframe);
will work. but if you really want to execute a function, you can do it more verbosely with:
gotoF();
function gotoF(){
var randomframe = Math.floor(Math.random() * _this.movieclip.totalFrames);
_this.movieclip.gotoAndStop(randomframe);
}
Copy link to clipboard
Copied
p.s. if you want to eliminate the need to use:
var _this=this;
you can use:
gotoF.bind(this)();
function gotoF(){
var randomframe = Math.floor(Math.random() * _this.movieclip.totalFrames);
this.movieclip.gotoAndStop(randomframe);
}
Copy link to clipboard
Copied
Thannk you.
Works perfectly.
And thanks for the extra tips!
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now