Skip to main content
Inspiring
September 8, 2023
Answered

Animate CC HTML5 canvas can't update a var on mouseover

  • September 8, 2023
  • 1 reply
  • 402 views

If any one can help!, I have 2 frames, first frame has a this.stop(); and I want to go to the second frame afer x seconds (11), but only if I havent already gone to the second frame by hovering a button object.

So srated with var _frame1 = "f1"; and tried to updated that with_frame1 = "f2"; on mouseover so the if statement wouldn't run the code for the second time.

var _frame1 = "f1";

if(_frame1 == "f1") {
	var t=setTimeout(function(){
	console.log(this, _this);
	_this.gotoAndPlay("frame2_play");
}, 11500);
}

this.ball_ani_3.ball_graphic_outer_frame1.ball_graphic_text.hotspot_outer.hotspot.addEventListener("mouseover", ballMouseOver3.bind(this));

function ballMouseOver1()
{
	//play
	var t=setTimeout(function(){
		console.log(this, _this);
		_this.gotoAndPlay("frame2_play");
	}, 1000);
	//set frame position
	_frame1 = "f2"
}

 

 

This topic has been closed for replies.
Correct answer kglad

there are a few problems with your code. try:

 

this.stop();
var _this=this;
stage.enableMouseOver();
 
setTimeout(gotoF,11500);
 
function gotoF(){
if(_this.currentFrame==0){
_this.gotoAndStop(1);
}
}
 
this.ball_ani_3.ball_graphic_outer_frame1.ball_graphic_text.hotspot_outer.hotspot​.addEventListener("mouseover", ballMouseOver1.bind(this));
 
function ballMouseOver1(){
_this.gotoAndStop(1);
}
 

1 reply

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
September 9, 2023

there are a few problems with your code. try:

 

this.stop();
var _this=this;
stage.enableMouseOver();
 
setTimeout(gotoF,11500);
 
function gotoF(){
if(_this.currentFrame==0){
_this.gotoAndStop(1);
}
}
 
this.ball_ani_3.ball_graphic_outer_frame1.ball_graphic_text.hotspot_outer.hotspot​.addEventListener("mouseover", ballMouseOver1.bind(this));
 
function ballMouseOver1(){
_this.gotoAndStop(1);
}
 
Inspiring
September 9, 2023

Thanks this work perfectly.

kglad
Community Expert
Community Expert
September 9, 2023

you're welcome.