开发者

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

开发者 https://www.devze.com 2023-03-25 19:15 出处:网络
There seems to be little support or discussion around regarding Google Swiffy (http://swiffy.googlelabs.com/).

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 prop开发者_Python百科erty be manipulated for example?


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();
});


Sorry for my english I'm french;) I was looking for a solution to be able to properly handle animation Swiffy. Since the new version (5.0) google code has changed and I can no longer maniupler animation with small hacks found on the net ... For cons, I coded force to find a solution .. which seems to me very simple and clean .. (without touching the source Swiffy!) In fact any part of this post : swiffy / javascript

Can be recovered with flashvars Swiffy (in as2 and as3 it should work too ..)

the side javascript can do this kind of things:

function playMovie(){
    stage.setFlashVars('myresponse=play');
    return false;
  }
  function stopMovie(){
    stage.setFlashVars('myresponse=pause');
    return false;
  }

and the side of the flash in a function enterFrame ... :

_root.onEnterFrame = function(){
switch(_level0.myresponse){
    case 'play':
        _root.play();
        break;

    case 'pause':
        _root.stop();
        break;

    default :
        break;
}
_level0.myresponse = undefined;
 }

and that's it! To you organize the methods you want but .. it works;) Must retake the undefined variable if you want to reuse it later ;)


Having un-minified the runtime.js - it was possible to achieve the behaviour I wanted.

On line 3312 (unminified - jsbeautifier.org)

M.start = function (arg) {
this.T[Qa]();
if(arg){
this.cb.start(arg)
}else{
this.cb.start()
}
};

And on line 3823:

M.start = function(arg)  {

    if(arg){
        console.log(arg);
        window.clearInterval(window.pauseAnimation)

    }else{
        window.pauseAnimation = window.setInterval(Ob(this.ne, this), 40 );
        if (!this.ie) this.ie = !0, this.ne(), window.pauseAnimation

    }     

};

Then using console, it is possible to pause/resume your animation using:

stage.start(true) // PAUSE the animation.
stage.start() // RESUME the animation.
0

精彩评论

暂无评论...
验证码 换一张
取 消