Highlighted

play from currentFrame and stop on targeted frames in animate CC (html5)

Community Beginner ,
Jul 23, 2020

Copy link to clipboard

Copied

I was struggling with this code and still not find correct way of doing this. so posted here.

 

All frame are in my nested movieclip (mc_1). now I want to go on target frame by clicking on the button inside movieclip from the currentFrame as shown in below image.
here is my code:

 

this.stop();

var a = this;

a.mc_1.t.addEventListener("click",test_1)
function test_1(){
if(a.mc_1.currentFrame > 0){
var tds = 29 +(a.mc_1.currentFrame-a.mc_1.currentFrame); //wanted to get targeted frame number
a.stage_freezeobject.gotoAndStop(tds); \\ this will directily jump onto frame29 but I wanted to play from current frame and stop on 29.
}

any help will much appreciate.

 

below are 2 examples of two different currentFrames and play direction whereas 1 direction is normal play and 2nd direction is reverse play. it will be good if both ways are possible, if not, then 1 of this will fullfill my need.

 

Captureaaa.JPG

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

when currentFrame > target frame, you need to start a loop (eg, ticker) to play backwards and if < play forwards.  eg

 

// assuming target is defined
function test_1(){
if(a.mc_1.currentFrame > target && !createjs.Ticker.hasEventListener("tick")){ 
createjs.Ticker.addEventListener("tick", reversePlayF);
} else if(a.mc_1.currentFrame < target && !createjs.Ticker.hasEventListener("tick")){ 
a.mc_1.play();
createjs.Ticker.addEventListener("tick", playF);
}
}
function reversePlayF() { a.mc_1.gotoAndStop(a.mc_1.currentFrame-1);
if(a.mc_1.currentFrame==target){
createjs.Ticker.removeEventListener("tick", reversePlayF);
}

function playF{
if(a.mc_1.currentFrame == target){
a.mc_1.stop();
createjs.Ticker.removeEventListener("tick", playF);
} }

Views

74

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more

play from currentFrame and stop on targeted frames in animate CC (html5)

Community Beginner ,
Jul 23, 2020

Copy link to clipboard

Copied

I was struggling with this code and still not find correct way of doing this. so posted here.

 

All frame are in my nested movieclip (mc_1). now I want to go on target frame by clicking on the button inside movieclip from the currentFrame as shown in below image.
here is my code:

 

this.stop();

var a = this;

a.mc_1.t.addEventListener("click",test_1)
function test_1(){
if(a.mc_1.currentFrame > 0){
var tds = 29 +(a.mc_1.currentFrame-a.mc_1.currentFrame); //wanted to get targeted frame number
a.stage_freezeobject.gotoAndStop(tds); \\ this will directily jump onto frame29 but I wanted to play from current frame and stop on 29.
}

any help will much appreciate.

 

below are 2 examples of two different currentFrames and play direction whereas 1 direction is normal play and 2nd direction is reverse play. it will be good if both ways are possible, if not, then 1 of this will fullfill my need.

 

Captureaaa.JPG

Adobe Community Professional
Correct answer by kglad | Adobe Community Professional

when currentFrame > target frame, you need to start a loop (eg, ticker) to play backwards and if < play forwards.  eg

 

// assuming target is defined
function test_1(){
if(a.mc_1.currentFrame > target && !createjs.Ticker.hasEventListener("tick")){ 
createjs.Ticker.addEventListener("tick", reversePlayF);
} else if(a.mc_1.currentFrame < target && !createjs.Ticker.hasEventListener("tick")){ 
a.mc_1.play();
createjs.Ticker.addEventListener("tick", playF);
}
}
function reversePlayF() { a.mc_1.gotoAndStop(a.mc_1.currentFrame-1);
if(a.mc_1.currentFrame==target){
createjs.Ticker.removeEventListener("tick", reversePlayF);
}

function playF{
if(a.mc_1.currentFrame == target){
a.mc_1.stop();
createjs.Ticker.removeEventListener("tick", playF);
} }

Views

75

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Jul 23, 2020 0
Adobe Community Professional ,
Jul 23, 2020

Copy link to clipboard

Copied

when currentFrame > target frame, you need to start a loop (eg, ticker) to play backwards and if < play forwards.  eg

 

// assuming target is defined
function test_1(){
if(a.mc_1.currentFrame > target && !createjs.Ticker.hasEventListener("tick")){ 
createjs.Ticker.addEventListener("tick", reversePlayF);
} else if(a.mc_1.currentFrame < target && !createjs.Ticker.hasEventListener("tick")){ 
a.mc_1.play();
createjs.Ticker.addEventListener("tick", playF);
}
}
function reversePlayF() { a.mc_1.gotoAndStop(a.mc_1.currentFrame-1);
if(a.mc_1.currentFrame==target){
createjs.Ticker.removeEventListener("tick", reversePlayF);
}

function playF{
if(a.mc_1.currentFrame == target){
a.mc_1.stop();
createjs.Ticker.removeEventListener("tick", playF);
} }

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 23, 2020 0
Community Beginner ,
Jul 23, 2020

Copy link to clipboard

Copied

Thank you so much.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 23, 2020 0
kglad LATEST
Adobe Community Professional ,
Jul 24, 2020

Copy link to clipboard

Copied

you're welcome.

Likes

Translate

Translate

Report

Report
Community Guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
Reply
Loading...
Jul 24, 2020 0