Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pause/resume/manipulate a swiffyobject from JS?

There seems to be little support or discussion around regarding Google Swiffy (http://swiffy.googlelabs.com/).

Is it possible to effectively pause/resume/manipulate a swiffyobject from JS?

Using standard Google output, I noticed the swiffyobject could be found in console with a few properties; notably frameRate. Could this property be manipulated for example?

like image 742
sgb Avatar asked Aug 02 '11 10:08

sgb


1 Answers

For the latest Swiffy release (Swiffy runtime version 5.2 https://www.gstatic.com/swiffy/v5.2/runtime.js) I did this.

1.Use jsbeautifier.org as mentioned in samb's post.

2.Find the function containing .start(). In my case...

db(N, function () {
    var a = this.Dg;
    this.ck(function () {
        a.start()
    })
});
db(Yj[I], Yj[I].start);

3.Duplicate this function with a different name, and replace start() with stop()

myNewFunction(N, function () {
    var a = this.Dg;
    this.ck(function () {
        a.stop()
    })
});
myNewFunction(Yj[I], Yj[I].stop);

4.Find the declaration of the function containing .start(). In my case db.

function db(a, b) {
    return a.start = b
}

5.Duplicate this function and call it the same as the new function you created with stop() in and replace start with stop. In my case myNewFunction.

function myNewFunction(a, b) {
    return a.stop = b
}

That's it.

Now you can call my anim.stop();

e.g.

//create anim
var anim = {swiffy code};
var myAnim = new swiffy.Stage(document.getElementById('animContainer'), anim);
myAnim.start();

//some button click
myButton.on('click',function(){
  myAnim.stop();
});
like image 170
r8n5n Avatar answered Sep 30 '22 17:09

r8n5n