dcsimg
A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: Prevent flash from reloading on page refresh

  1. #1
    Junior Member
    Join Date
    Aug 2007
    Posts
    4

    Prevent flash from reloading on page refresh

    Can someone tell me how I can prevent flash from reloading when my page is refreshed? When I user clicks the search button the whole page reloads with the data they were looking for but the flash animation at the top of the page also reloads and I would like to prevent this. Can someone point me in the right direction?

  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    you can use a shared Object (flash cookie)...

    you can then set a variable (played = true) for example..
    and check that EACH time your movie loads.. if it reads the shared object and it says played = true, then it wont run again.. it played = false or undefined, you can then play your movie..

    I have a link on shared object in my footer on to use one if you want to check it out.

  3. #3
    Junior Member
    Join Date
    Aug 2007
    Posts
    4
    I did find some code to help with what I am looking for...

    var today = new Date();
    var so:SharedObject = SharedObject.getLocal("time");
    var period = 15000;

    ---------------------------------------------------------------------------------------------------

    if (loaded == total)
    {
    if (!((_root.today-_root.so.data.val)<_root.period))
    {
    _root.so.data.val = _root.today;
    _root.so.flush();
    _root.gotoAndPlay(2); //full animation
    }
    else
    {
    _root.so.data.val = _root.today;
    _root.par = "skip";
    _root.gotoAndStop(20);
    }
    }

    I put the first three lines of code into frame 1 of my movie and then I pasted the rest into the animation that starts on frame 1. I made a real simple animation of a ball bouncing to see if it would work but the animation doesn't play smoothly. I took out the _root.gotoAndStop(20); and the animation played fine but then it just goes to frame 1 of the movie and not frame 20 which is the end.

    Anyone have any suggestions?

  4. #4
    Junior Member
    Join Date
    Aug 2007
    Posts
    4
    I don't really understand whispers what you are explaining on the shared object page. Is there any way you and I could go over it and I will show you the project I am looking to do it for?

  5. #5
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    you can try this:

    see if this helps:

    summary:

    it does a check to see if the cookie is set to TRUE (already been played).. if it is (FALSE) not true (or undefined...ie: not created) then it creates the cookie and sets the var to TRUE for he next 'check'.

    Code:
    //load your sharedObject called 'displayCookie'
    var mySharedObject:SharedObject = SharedObject.getLocal("displayCookie");
    if(mySharedObject.data.displayed == true){
        //do whatever IF already been played
    	trace("cookie found");
    }else{
    	trace("cookie not found, setting it now");
    	//do whatever if NOT already been played
        mySharedObject.data.displayed = true;
        mySharedObject.flush();
    }

  6. #6
    Junior Member
    Join Date
    Aug 2007
    Posts
    4
    Maybe I should learn actionscript before asking such crazy questions...of which I know nothing about.

  7. #7
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    I figure someone is going to want to kill me for reviving a thread from 2007. It seems like I do not have any permissions to send the user "whispers" above a private message. So my apologies. I have been through every relevant search result goolgle has to offer on this issue and this thread was piece 1 of 2 of the puzzle. Every other result on the net all ended the same way.. Unanswered.. What the problem is for most of the answer seekers I ran across were like myself. Just started learning flash like 2 days ago I would say.

    Longer story shorter I got this to work finally moments ago. But something is still wrong. I too just like the thread starter have the a flash object in my case a site navigation header that was reloading after every click and would play music and animation over every time an html page was navigated to and from. So now with whispers above advice I started to study and study what I needed to accomplish using that example.

    So as of right now when you first arrive on page it plays the full .swf which is what I wanted. Then when you refresh that same page the .swf is stationary without all of the start up animation and music. The problem is its only for that page. The next page on the site that I visit will reload all animation but again if that new page is refreshed again it is stationary with the cookie set. After I view all of the animation for example lets say 5 pages then upon returning to those pages they in fact stay stationary.. I want this thing to stay still through the entire visit to the site after the initial home page visit. The cookie is having to be applied on every page hit.

    Here is what I have.

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

    gotoAndPlay(120); 
    }else{
        
    mySharedObject.data.displayed true;
        
    mySharedObject.flush();


    Any ideas why this is happening to me.. The cookie should not need to be set for every page that is visited.

    Again sorry for old thread revival but this was the only worthy information located on the internet.

  8. #8
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    I believe you need a higher post count to enable PM's..(nto sure what that count is though.)

    my 'thoughts' are maybe your not writing checking the 'same' SO?

    I'll have to look into it..if I remember correctly..I think there was aline of code to add ro something to path to the same/correct SO object

  9. #9
    Junior Member
    Join Date
    Mar 2010
    Posts
    2
    I will be keeping it at it but let me know if anything comes to you.. It also seems like my cookie is expiring with in a minute or couple minutes time. I can visit 4 pages and have the cookie set on all 4 and then walk away from the computer and when I come back the page does a full load again with full animation like the cookie is gone and as to set again. I catching on to this stuff way faster than I thought I would but I was already familiar with Photoshop and other programs. It helped.

  10. #10
    Member
    Join Date
    Sep 2010
    Posts
    43
    Hi...
    This worked for me to stop my flash banner to reload when visiting other links..
    But it worked in IE not in Firefox. Any solutions?

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