Copy link to clipboard
Copied
I use the code below to manipulate.
Use gotoAndStop to jump to this frame,
will be again "var kg = True"
Causes the button to click again.
Is there any other way to make the button perform only 1 times?
var kg = true
this.on("click", pd);
function pd()
{
if(kg)
{
this.play();
kg = false
}
}
this.stop();
use:
if(!this.alreadyExecuted){
this.alreadyExecuted=true;
var pdF=pd.bind(this);
this.addEventListener('click',pdF);
}
function pd(){
this.removeEventListener('click',pdF);
this.play();
}
Copy link to clipboard
Copied
among the ways to do this:
var alreadyExecuted;
if(!alreadyExecuted){
alreadyExecuted=true;
var pdF=pd.bind(this);
this.addEventListener('click',pdF);
}
function pd(){
this.removeEventListener('click',pdF);
this.play();
}
Copy link to clipboard
Copied
The code is still invalid,
When the movie loops and then jumps to the start, the button can be executed again, unable to implement 1 times.
Copy link to clipboard
Copied
Just use on with the "once" flag set.
https://createjs.com/docs/easeljs/classes/EventDispatcher.html#method_on
this.on("click", this.play, this, true);
And DON'T let your movie loop to the start.
Copy link to clipboard
Copied
Everyone's methods have been tried,
When you jump to this frame, it will count again.
Copy link to clipboard
Copied
Sometimes for this kind of problem I use a variable like
var active = 1;
if(active ==1){
// do something
active = 0;
}
This way since your variable has been set to 0 the action will not repeat since it is not reset to 1 if that makes sense.
Copy link to clipboard
Copied
If you jump to this frame again.
Active will be equal to 1 again.
It caused the failure.
If you write to the global function directly then there is no problem.( active = 1;Do not use Var)
I want to know the way to not use global functions.
Copy link to clipboard
Copied
Then do not go back to the initial frame. I put most of my code on frame 1 and then control everything from there. I have been totally successful controlling plays exactly as I want especially when I want something to happen only once.
Copy link to clipboard
Copied
Because special needs must jump to the code frame.
Fortunately, it is. Kglad's answer was implemented only once
Copy link to clipboard
Copied
use:
if(!this.alreadyExecuted){
this.alreadyExecuted=true;
var pdF=pd.bind(this);
this.addEventListener('click',pdF);
}
function pd(){
this.removeEventListener('click',pdF);
this.play();
}
Copy link to clipboard
Copied
Thank you, really only executed once, thank you very much.
Copy link to clipboard
Copied
you're welcome.