2 Replies Latest reply on Mar 22, 2007 4:40 AM by Newsgroup_User

    How do I stop a swf file restarting on a html page refresh

    curtisontour
      Hi

      I've looked around the usual haunts for help on this topic so I thought I come here, as I probably should have to begin with.

      I have a swf file that appears at the top of every html page on a site that I'm working on... every time a user changes the page they are looking at the swf movie restarts... It's essential that the movie runs to the end as that is where the clients final splash appears.

      How can I stop the swf restarting and continue playing from where it was before the page change/refresh?

      thanks in advance for any help.


      Curtis
        • 1. Re: How do I stop a swf file restarting on a html page refresh
          Level 7
          A SharedObject should do what you need:


          var so = SharedObject.getLocal("framecookie");
          if (so.data.frame != undefined) {
          if (so.data.frame == this._totalframes) {
          this.gotoAndPlay(1);
          } else {
          this.gotoAndPlay(so.data.frame);
          }
          }
          //
          this.onEnterFrame = function() {
          so.data.frame = this._currentframe;
          };


          When you start, the object is checked and if the frame number is defined it
          goes to it and begins play. If it's on the last frame then it will start
          over. The enterFrame attached to root writes the current frame number to the
          object on every frame...

          HTH



          --
          Dave -
          Head Developer
          www.blurredistinction.com
          Adobe Community Expert
          http://www.adobe.com/communities/experts/


          • 2. Re: How do I stop a swf file restarting on a html page refresh
            fasilak@gmail.com
            Use the javascript function to set a cookie
            Add this javascript function into your html page. This sets a cookie based upon the parameters passed.
            For more about the function check the below url:
            http://techpatterns.com/downloads/javascript_cookies.php


            <script type="text/javascript">
            function Set_Cookie( name, value, expires, path, domain, secure )
            {
            // set time, it's in milliseconds
            var today = new Date();
            today.setTime( today.getTime() );

            /*
            if the expires variable is set, make the correct
            expires time, the current script below will set
            it for x number of days, to make it for hours,
            delete * 24, for minutes, delete * 60 * 24
            */
            if ( expires )
            {
            expires = expires * 1000 * 60 * 60 * 24;
            }
            var expires_date = new Date( today.getTime() + (expires) );

            document.cookie = name + "=" +escape( value ) +
            ( ( expires ) ? ";expires=" + expires_date.toGMTString() : "" ) +
            ( ( path ) ? ";path=" + path : "" ) +
            ( ( domain ) ? ";domain=" + domain : "" ) +
            ( ( secure ) ? ";secure" : "" );
            }


            function Get_Cookie( name ) {

            var start = document.cookie.indexOf( name + "=" );
            var len = start + name.length + 1;
            if ( ( !start ) &&
            ( name != document.cookie.substring( 0, name.length ) ) )
            {
            return null;
            }
            if ( start == -1 ) return null;
            var end = document.cookie.indexOf( ";", len );
            if ( end == -1 ) end = document.cookie.length;
            return unescape( document.cookie.substring( len, end ) );
            }

            </script>

            In flash write this code

            if(currentFrame!=undefined){
            this.gotoAndPlay(currentFrame);
            }
            onEnterFrame=function(){
            getURL("javascript:Set_Cookie( 'currentFrame', '"+_currentframe+"', '', '/', '', '' ) ");
            }


            Using the help of this URL
            http://oddhammer.com/tutorials/firefox_setvariable/


            You can learn how to set values back from javascript to flash

            Take the cookie value in javascript using Get_Cookie method
            in your html page and then set that value to flash.

            Hope this helps.