Looking to halt the execution of a tween animation

I have implemented some tweens but now I need to pause them

Because I want to reuse certain assets with new tweens. The 'override:true' option helps in some cases, but...

This is the issue: once the function is triggered and the timers are set, the tweens play continuously regardless of callbacks.

window.autoSurfaces = function(){
if(!window.gameStarted){ 
console.log("autoSurfaces");
playAutoScene();//function to initiate number and alpha controls for wheels
var delay = 700
var animtime = 500

currentTween = createjs.Tween.get(leaves_anim).to({alpha:.7}, animtime).wait(800).call(leavesOut);//callback to end frame function
tweenAray.push(currentTween)
console.log(currentTween)
leaves_anim.gotoAndPlay("go");

    function leavesOut(){
    currentTween = createjs.Tween.get(leaves_anim).to({alpha:0}, animtime).wait(200).call(snowIn);
    tweenAray.push(currentTween)
    console.log(currentTween)
     }

    function snowIn(){
    currentTween = createjs.Tween.get(snow_anim).to({alpha:1}, animtime).wait(800).call(snowOut)
    tweenAray.push(currentTween)
    console.log(currentTween)
    snow_anim.gotoAndPlay("go");
     }

     function snowOut(){
    currentTween = createjs.Tween.get(snow_anim).to({alpha:0}, animtime).wait(delay).call(stopAll);
    tweenAray.push(currentTween)

     function stopAll(){
     playAutoOut();
     leaves_anim.gotoAndStop(0);
     snow_anim.gotoAndStop(0);

        }
     }
 }

}

I initialized a global variable named currentTween and then:

currentTween = createjs.Tween.get(target).to({alpha:.7}, animtime).wait(800).call(callHandler);

and after that:

removeTweens(currentTween);

I attempted to use an array - tweenArray.push(currentTween)

tweenArray.removeTweens(currentTween)

Moreover, createjs.Tween.removeAllTweens();

Even

createjs.Tween.removeAllTweens = function() {
var tweens = createjs.Tween._tweens;
for (var i=tweens.length-1; i>=0; i--) {
    tweens[i]._paused = true;
    tweens.splice(i,1);
}

};

However, nothing seems to work or sometimes errors occur. I am exporting from Flash CS6.

Any suggestions?

Cheers

Answer №1

Your question is a bit unclear to me, but here's my attempt at addressing it...

When you use the override property, any new tween will stop previous tweens targeting the same object. For example:


createjs.Tween.get(foo).to({x:100, alpha:0.5}, 200);
createjs.Tween.get(foo, {override:true}).to({x:500}, 500);

In this scenario, the second tween will override the first one because they both target foo. The first tween will be interrupted and won't run.

If you need to stop tweens completely, keep references to them and use setPaused(true) to kill them off:


var tweensToStop = [];
tweensToStop.push( new createjs.Tween.get(foo).etc(...) );
tweensToStop.push( new createjs.Tween.get(bar).etc(...) );
// ... later:
while (tweensToStop.length) {
    tweensToStop.pop().setPaused(true);
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Puzzled on how to include a string in the parameter for a GET request?

Following the initial instruction to make a get request for a turtles route and send a JS object of turtles with their colors, I successfully implemented it like this: app.get('/turtles', function(req, res) { data = { Raphael: "Red", Le ...

JavaScript - Unexpected fluctuations in variable values

After studying Japanese language, I decided to try my hand at experimenting with JavaScript by creating a simple FlashCard game for a project. The game generates an array of random numbers, fills the divs with 6 possible choices using jQuery, randomly sele ...

What is the best way to use checkboxes to highlight table rows in Jquery Mobile?

I have a Jquery Mobile site with a table. Each table row contains checkboxes in the first cell. I am trying to achieve the following: a) Highlight a row when the user clicks on it b) Highlight a row when the user checks the checkbox I have made progr ...

Update the content of the widget

Currently, I am utilizing the following script to display NBA standings: <script type="text/javascript" src="https://widgets.sports-reference.com/wg.fcgi?script=bbr_standings&amp;params=bbr_standings_conf:E,bbr_standings_css:1&amp"></sc ...

Deactivate particular JavaScript when displaying a Bootstrap modal

On mobile devices, I have JavaScript that is preventing vertical panning on modals, resulting in users not being able to see all the modal content. Is there a way to disable this JavaScript when a modal is displayed? The following snippet of JavaScript a ...

Error: There was a syntax issue when trying to parse JSON due to an unexpected identifier "object" in the anonymous function

I'm having trouble understanding why there was an issue parsing this file: { "t": -9.30, "p": 728.11, "h": 87.10 } This is the javascript code I used: <script type="text/javascript"> function verify() { $.get("http://....file.json", funct ...

Stop mega menu items from disappearing when hovered over

I'm currently working on a web page that features a mega menu. When I hover over the mega menu, it displays its items. However, when I try to hover over the items, they disappear. Here is the HTML code snippet: <li class="dropdown mega-dropdown m ...

Navigating views with ReactJS using ES5

I have been searching for ReactJs guides, but most of them are based in ES5. As a result, I have begun using ReactJS in this manner. Now that I understand how to create all my components, I am ready to build a small single-page-application. However, I am s ...

Issue with Gulp and Browserify task: Why is there no output?

I've set up the following task in my gulpfile.js gulp.task('default', ['browserify']) gulp.task('browserify', function () { return browserify('./public/js/x.js') .bundle() .pipe(source('y.js& ...

Latest Information Regarding Mongodb Aggregate Operations

Struggling to toggle a boolean value within an object that is part of a subdocument in an array. Finding it difficult to update a specific object within the array. Document: "_id" : ObjectId("54afaabd88694dc019d3b628") "Invitation" : [ { "__ ...

Three.js interpolation surface solution

Greetings everyone, I have a question regarding surfaces in Three.js. I have multiple Vec3 points and I want to create a surface that interpolates through them. While researching, I came across bezier curves (source: three.js bezier - but only as lines) a ...

What is the most effective way to transfer information between two pages in React JS?

I am a newcomer to react and currently working on a project that involves two pages/components. I collect user details on one page and need to display that data on another page. However, I am facing difficulties in achieving this. Can someone please provid ...

Context Provider executing SetInterval twice

For some reason, the below code in global.js is running twice when I run my react app, but I can't figure out why. I have used setInterval to test, and the intervals are always running two times. Perhaps I am not initializing correctly. Even after rem ...

What is the best way to display a removed item from the Redux state?

Display nothing when the delete button is clicked. The issue seems to be with arr.find, as it only renders the first item regardless of which button is pressed, while arr.filter renders an empty list. reducer: export default function reducer(state = initi ...

The data source is having trouble connecting to the updated JSON format due to issues with pagination

I'm utilizing pagination.js to fetch asynchronous data using the code below. $('#demo').pagination({ dataSource: 'https://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any&format=json&jsoncallback=?&ap ...

The PHP function is returning an undefined value in JavaScript

I feel like there must be a simple solution to this problem that I just can't seem to find. Everything related to PHP search functions and queries is functioning properly, except for the fact that the data isn't displaying correctly in the text a ...

Nested jquery tabs

Similar Question: Unable to get jquery tabs nested I am trying to create a nested tab, but haven't found a satisfactory solution through my research. Can anyone provide me with some guidance? I have limited experience in JavaScript or jQuery prog ...

Basic JavaScript string calculator

I'm in the process of creating a basic JavaScript calculator that prompts the user to input their name and then displays a number based on the input. Each letter in the string will correspond to a value, such as a=1 and b=2. For example, if the user e ...

Troubleshooting CodeIgniter's AJAX call functionality issue

I have been attempting to test AJAX functionality within CodeIgniter, but unfortunately, I haven't had any success so far. Can someone please point out where I might be making a mistake? Below is my test_page.php: <!DOCTYPE html> <head> ...

Check if an array includes a specific value, and then either update it if found, or create it

I'm currently working with a Cart object in Javascript and I need to check if a specific item is present in the cart. Here's my approach: If the item is already in the cart, update its quantity. If it's not in the cart, add it to the items ...