Skip to main content
Inspiring
January 20, 2024
解決済み

In Animate HTML5 canvas on named last frame of movie clip gotoAndStop on named main timeline frame

  • January 20, 2024
  • 返信数 1.
  • 2474 ビュー

I have a movie clip on stage on top of a graphic. When the main timeline movie gets to this frame it stops and plays the nested movie clip. I want to code from the main timeline actionscript layer an event listener that detects when the last named frame of the nested clip is played and goto and stop on a named frame of the main timeline.

 

So, for example.

 

On frame 30 which is named "question_1" is a button click event listener that goes to the next frame "question1_answer1":

 

this.q1f1.addEventListener("click", fl_MouseClickHandler.bind(this));

function fl_MouseClickHandler()
{
      this.gotoAndStop("question1_answer1");

}

 

on "question1_answer1" there is a "this.stop();" and a movie clip on the stage named "qchicken" that runs an animation. On the last frame of "qchicken" I have named the frame "chicken_down" at which point I want to go back to "question_1" on the main timeline. So how do I write an event listener that does this:

 

this.qchicken.EVENT LISTENER THAT DETECTS WHEN "chicken_down" IS REACHED.parent.gotoAnd Stop("question_1");

 

And finally, how and where do I put the remove event listener code once the goto is executed (and similarly once a button is pressed on other events)? I've seen more than one variation of writing remove event listener in posts and examples of it being placed before and after the event code. Which is correct?

 

 

 

このトピックへの返信は締め切られました。
解決に役立った回答 Charles_I

no, you should explicitly stop it.

 

 
var _this = this;
var chicken_downFF = chicken_downF.bind(this);
createjs.Ticker.addEventListener("tick", chicken_downFF);
 
function chicken_downF() {
 
if (_this.qchicken.currentLabel == "chicken_down") {
createjs.Ticker.removeEventListener("tick", chicken_downFF);
}
}

Thanks. So, with the gotoAndStop line the complete working

var _this = this;
var chicken_downFF = chicken_downF.bind(this);
createjs.Ticker.addEventListener("tick", chicken_downFF);

function chicken_downF() {

	if (_this.qchicken.currentLabel == "chicken_down") {
		createjs.Ticker.removeEventListener("tick", chicken_downFF);
		_this.gotoAndStop("question_1");
	}
}

code looks like this:

 

返信数 1

kglad
Community Expert
Community Expert
January 20, 2024

var _this=this;

createjs.Ticker.addEventListener("tick",this.chicken_downF);

 

function chicken_downF(){

if(_this.qchicken.frameLabel=="chicken_down"){

createjs.Ticker.removeEventListener("tick",this.chicken_downF);

_this.gotoAndStop("question_1");

}

}

Charles_I作成者
Inspiring
January 22, 2024

Hmm, not working for me.  I put the function in the actionscript layer on the frame with the qchicken movie. And I tried putting an alert after the "if...frameLabel" line but nothing happens - the program doesn't reaches it.  Interestingly, if I put an alert in before the function it fires on the mousedown of the previous  frame before it reaches the frame where the qchicken movie is.

 

Also, I don't understand the reason for creating this variable, "var _this=this;". It appears to me where "_this"  is being used is still the same place where "this" is required as a key word.

Charles_I作成者
Inspiring
February 6, 2024

i have no idea why i typed this.chicken_downF.  that should be chicken_downF.bind(this)


So I tried this, and as before the function is not being reached because both alerts come up as "no." I might just have to go with putting the code in the movie clip which works fine.

 

var _this = this;
var yesno = "no";

alert(yesno);

createjs.Ticker.addEventListener("tick", chicken_downF.bind(this));

function chicken_downF() {

	if (_this.qchicken.frameLabel == "chicken_down") {

		yesno = "yes";
		return yesno;

	}
		alert(yesno);

}