11 Replies Latest reply on Sep 26, 2011 3:46 PM by agon024

    Preventing swf from Reloading on page refresh

    agon024 Level 1

      Flash CS5, CS4

      Actionscript 2

       

      Hi everyone. Good day to you all.

       

      What I want the SWF to do is play from the beginning when someone hits the index.php file and gotoAndStop(234) when someone goes to a sub-page (like contact.htm).

       

      What I did first was:

      [code]
      function checkSO() {
      var SO = SharedObject.getLocal("siteSO");
      if (SO.data.visitedAlready != undefined) {
      this.gotoAndPlay(234);
      }
      else {
      SO.data.visitedAlready = "yes";
      SO.flush();
        }
      }
      checkSO();
      [/code]

       

      And that worked in the sense of no cookie-it loads and plays the swf from the beginning. If there is a cookie it starts from frame 234.

       

      As it sits now as long as the cookie exist in the TIF everytime they return to my page it will not play the opening animation it will just jump to then end even on the index.php.

       

      Someone else suggested:

      [code]
      import flash.external.*;
      var currentURL:String = String(ExternalInterface.call("window.location.href.toString"));
      if ('http://www.blahblah.com/test/index.php' == currentURL) {
      /** ...flush.. **/

      }
      else {
        gotoAndStop(234)
      }
      [/code]

       

      I just don't know what string (I think) to put in the /** ...flush.. **/ part

        • 1. Re: Preventing swf from Reloading on page refresh
          kglad Adobe Community Professional & MVP

          what's the problem with using your sharedobject?

          • 2. Re: Preventing swf from Reloading on page refresh
            agon024 Level 1

            I have tried:

             

             

            var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");
            if(mySharedObject.data.displayed == true){

            gotoAndStop(235);
            }else{
                mySharedObject.data.displayed = true;
                mySharedObject.flush();

            }

             

             

            But when that is in the first frame it doesn't load because the following frame contains a movie clip that is calling my "page loading" AS.

             

             

            onClipEvent (load) {

            total = _root.getBytesTotal();

            }

            onClipEvent (enterFrame) {

            loaded = _root.getBytesLoaded();

            percent = int(loaded/total*100);

            text = ""+percent+"%";

            gotoAndStop(percent);

            if (loaded == total) {

              _root.gotoAndPlay(3);

            }

            }

             

            if i put it after the frame that contains the clip that is calling the "page loading" AS it just jumps to frame 234 because my guess is by the time the loader has finished loading the content it has already placed a cookie in the browsers TIF.

            • 3. Re: Preventing swf from Reloading on page refresh
              kglad Adobe Community Professional & MVP

              no code should be attached to objects (but that's a different issue).  you can use:

               

              frame 1:

              stop();

              // and place your preloader movieclip here.

               

              frame 3 or beyond:

              var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");
              if(mySharedObject.data.displayed == true){

              gotoAndStop(235);
              }else{
                  mySharedObject.data.displayed = true;   // not sure if this is the correct place to assign displayed to your so
                  mySharedObject.flush();

              }

              • 4. Re: Preventing swf from Reloading on page refresh
                agon024 Level 1

                Thanks for your replies and all the help you have given me so far.

                 

                I have already tried that... If I put the preloader on frame 1 it will not go to frame 3 until the page is loaded....By that time the cookie is already dropped in the TIF and it will jump to my end frame every time.

                 

                I have already made what your talking about work by using:

                 

                function checkSO() {

                var SO = SharedObject.getLocal("siteSO");

                if (SO.data.visitedAlready != undefined) {

                this.gotoAndPlay(234);

                }

                else {

                SO.data.visitedAlready = "yes";

                SO.flush();

                }

                }

                checkSO();

                 

                But like I said up top with "CheckSO" and "SharedObject" if the cookie exists it jumps to the last frame like I want EXCEPT when they come back the next day and browse to the page, the cookie still exists so it jumps to the end frame..not playing the animation again until they empty their cookies.

                 

                I want it to jump to the end frame ONLY when they browse to a subpage. When they hit the index.php I want it to play the animation from the beginning. So cookies won't work in this situation without some sort of "except" variable or something (I am not and expert in AS which is why I am asking).

                 

                Is there a way to tell the code not to go to that frame if the user is on index.php?

                • 6. Re: Preventing swf from Reloading on page refresh
                  agon024 Level 1

                  sorry..Temporary Internet Folder.

                   

                  What about this...is there a script I can implement that says something like...if the current URL is index.php gotoAndPLay(2) else  gotoAndPlay(234)

                  • 7. Re: Preventing swf from Reloading on page refresh
                    kglad Adobe Community Professional & MVP

                    the so is not stored in your tif.

                     

                    do you have the same swf embedded in more than one html page? 

                     

                    if yes, and you want to skip that intro, you can use a time/date variable in your so to deteremine when to skip your intro.

                    • 8. Re: Preventing swf from Reloading on page refresh
                      agon024 Level 1

                      yes I have the same SWF embedded on 6 pages. Every time you click a link like aboutus.htm the swf it will start from the beginning animation. I want the animation only to start from the beginning only when they hit he index.htm. All the other pages (with the same SWF file) I want it to skip to frame 234.

                       

                      With regards to the TIF I was saying that the cookie is located in the TIF(right?). And by the time the preloader has finished loading the content the cookie has already been placed in the TIF. But if you have a way to avoid the cookie I would be interested .

                      • 9. Re: Preventing swf from Reloading on page refresh
                        kglad Adobe Community Professional & MVP

                        how do you open your other pages?  are you using getURL()?

                         

                        if yes, you can append a query string to your other html calls.  see the last section of:  http://kb2.adobe.com/community/preview/918/cpsid_91887.html

                        • 10. Re: Preventing swf from Reloading on page refresh
                          agon024 Level 1

                          Yes. I am using getURL("page.htm")

                           

                          someone else suggested:

                           

                          current_url = this._url;

                          url_split = current_url.split("/");

                          basename = url_split[url_split.length-1];

                          if(basename == "index.php"){

                              gotoAndPlay(2);

                          } else {

                              gotoAndPlay(234);

                          }

                           

                          And that partially works. The problem there is even when you go to http://www.blahblah.com/ or http://www.blahblah.com/index.php it still jumps to frame 234. When you go to the subpages like contact.htm it goes to frame 234 like I want. But I need it to start from frame 2 if it is the index.php. Any ideas?

                          • 11. Re: Preventing swf from Reloading on page refresh
                            agon024 Level 1

                            SOLVED!!

                             

                            Thanks to a genius named Prid from the actionscript.org forums. Here is what he gave me (obviously you replace domain.com with your domain, index.php with your default index page, and the frame numbers to what you want).

                             

                            current_url = flash.external.ExternalInterface.call("function(){return window.location.href}").toString();
                            url_split = current_url.split("/");
                            basename = url_split[url_split.length-1];
                            basename2 = url_split[url_split.length-2];
                            if(basename == "index.php"){
                                gotoAndPlay(2);
                            } else if((basename2 == "www.domain.com" || basename2 == "domain.com") && basename == ""){
                                gotoAndPlay(2);
                            } else {
                                gotoAndPlay(234);
                            }

                             

                            The javascript function returns this address, no matter how they type the path to your website, like if they type, domain.com, domain.com/, or http://domain.com, the path will always be returned in this format:

                             

                            http://www.domain.com/ OR http://domain.com/

                             

                            Notice that there's always a slash at the end of the URL address. By seperating the string with slash as the seperator, the last item will be the empty space after the last slash, so, we can check if the item before the last one is equals to your website AND also if the last item is equals to nothing!