How can I restart an swiffy animation after it has been completed

2.1k views Asked by At

I am new to swiffy. It works great the first time an animation is called but I need to reuse the animation later in the same page (a web app). How should I do?

To isolate the problem, I have tried something very basic that does not work:

<button onclick="stage.start();">Start</button>
<div id="swiffycontainer" style="width: 400px; height: 400px">
</div>
<script>
var stage = new swiffy.Stage(document.getElementById('swiffycontainer'),
                               swiffyobject);
</script>

Pressing on the button for the first time does start the animation When the animation is complete, pressing again does nothing.

Any help?

TIA

1

There are 1 answers

0
Leonard Feehan On

From memory you need to do some gotoandplay stuff in your flash file to send the animation back to the start and call into some flag to trigger that with stage.setFlashVars('flag=' + value);

However a quicker solution is to reload the swiffy object. make your onclick point to a replay function

   <script>
   var stage;
   var swiffyobject = "....whatever";
   //your initial load goes here
   stage = new swiffy.Stage(document.getElementById('swiffycontainer'), swiffyobject);

    function replay(){
       if(stage)
          stage.destroy();
       stage = new swiffy.Stage(document.getElementById('swiffycontainer'), swiffyobject);
       stage.start();
    }
    </script>

    <button onclick="replay()">Start</button>