A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Preventing swf from Reloading on page refresh

  1. #1
    Junior Member
    Join Date
    Oct 2007
    Posts
    3

    Exclamation Preventing swf from Reloading on page refresh

    Flash CS5, CS4
    Actionscript 2

    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.hre f.toString"));
    if ('hxxp://xxx.blahblah.xxx/test/index.xxx' == currentURL) {
    /** ...flush.. **/

    }
    else {
    gotoAndStop(234)
    }
    </CODE>

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

  2. #2
    Junior Member
    Join Date
    Oct 2007
    Posts
    3
    What about this...is there a script I can implement that says...if the current URL is index.php "gotoAndPLay(2) else gotoAndPlay(234)

  3. #3
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Location
    Norway
    Posts
    1,864
    Actionscript Code:
    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);
    }

    The first variable fetches the current URL, like the whole huge address. The second variable seperates the address with a slash, so that we can access each name in between the slashes, individually. Since index.php will probably be located at the address, we find the last piece in the seperated url, and then check if that string is equals to index.php
    I am back, guys ... and finally 18 :P

    BRING BACK THE OLD DESIGN!! OR AT LEAST FIX THE AS TAGS

  4. #4
    Junior Member
    Join Date
    Oct 2007
    Posts
    3
    SOLVED!!

    Thanks to a genius named Nig 13. 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).

    Code:
    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!
    Last edited by Agon024; 09-26-2011 at 06:43 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center