views:

603

answers:

2

Hi guys,

How would it be possible to have a HTML page play a flash animation only once, i.e. when a person goes back to that page, the Flash won't play again from the start but will just show the last frame of the animation (or even a simple .jpg image of that last frame)? Is it even possible?

Thanks, L.

+6  A: 

you could save a cookie the first time the user visits to show that the user has visited before. (http://plugins.jquery.com/project/Cookie)

Then when they return pass that value to the flash (using flashvars) so it knows only to play the last frame. (http://bowievanling.com/blog/using-flashvars-with-swfobject-20-and-as3/)

Using swfObject to embed your flash:

<script type="text/javascript">

var flashvars = {
  iscookie: "true"
};
var params = {
  menu: "false"
};
var attributes = { };

swfobject.embedSWF("myContent.swf", "myContent", "300", "120", "9.0.0","expressInstall.swf", flashvars, params, attributes);

</script>

in AS3 to load frameNumber if flashvar iscookie = true:

for (var fv in root.loaderInfo.parameters) {
   if(fv == 'iscookie'){
      if(root.loaderInfo.parameters[fv] == 'true'){
         gotoAndStop(frameNumber);
      }
   }
}

Josh

Josh
Thanks Josh, you've put me on the right track. I've still gotta figure out how to tell Flash to go to the last frame when the user revisits. Any ideas?
lorenzium
what version of actionscript are you using?
Josh
I'm using Action Script 3
lorenzium
+1  A: 

Alternativly to normal cookies, you could use Flash SharedObject. It pretty much like a normal cookie, but you access them via ActionScript, so it might be easier if are authoring the Flash movie yourself. You just save a simple boolean, and then the Flash movie can see it the next time it opens and will know just to display the end frame.

You can read about them here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/net/SharedObject.html

Lillemanden
are shared objects reliable enough? "Sometimes SWF files may not be allowed to write local shared objects, and sometimes the data stored in local shared objects can be deleted without your knowledge."
Josh
It is the same for cookies. The default settings in Flash allows for shared objects, so it should not be a problem in most situations.You can check for errors in case the user does not allow shared objects.
Lillemanden