Solved

Have Flash Remember Frame For When Page Reloads

Posted on 2004-10-27
184 Views
Last Modified: 2008-01-16
I have an image rotator on my left nav that I did manually with tweens, each image is linkable to different web pages.  The links open in the same window using _self.  Normally the movie will start over at the beginning on reload, then play to the end and loops forever back to frame 45.  What I am trying to do is have the flash movie start from where it left off using some sort of cookie when the movie reloads on the next page.

Need something like this: When the link is clicked in flash, need to save current frame somehow.  On the next page that loads, if recorded frame is in between of equal to:

45 - 165 - after new page loads start at 165
165 - 285 - start at 285
285 - 405 - start at 405
405 -  525 - start at 525
525 - 645 - start back at 45

What's the best way to do something like this?  I'm not sold on cookies.  Any help would be awesome.


0
Question by:madasczik
    8 Comments
     
    LVL 27

    Accepted Solution

    by:
    (Suppose your image rotator is inside a movieclip called rotator_mc)

    In the first frame of your movie:

    _root.so = SharedObject.getLocal("flashcookie");
    if(_root.so.data.rotator == undefined){
          _root.so.data.rotator = 45;
          _root.so.flush();
    }else{
          _root.rotator_mc.gotoAndPlay(_root.so.data.rotator);
    }
    function gotolink(link)
    {
          if(_root.rotator_mc._currentframe <= 45 || _root.rotator_mc._currentframe > 525){
                _root.so.data.rotator = 45;
          } else if(_root.rotator_mc._currentframe <= 165){
                _root.so.data.rotator = 165;
          } else if(_root.rotator_mc._currentframe <= 285){
                _root.so.data.rotator = 285;
          } else if(_root.rotator_mc._currentframe <= 405){
                _root.so.data.rotator = 405;
          } else if(_root.rotator_mc._currentframe <= 525){
                _root.so.data.rotator = 525;
          }
          _root.so.flush();
          getURL(link, "_self");
    }


    your links:

    on(release){
          _root.gotolink("page.html");      
    }
    0
     

    Author Comment

    by:madasczik
    Simply amazing code!!
    0
     

    Author Comment

    by:madasczik
    What you gave me works great, but I have once again butchered it.  Im passing in a flashvar of the base url but the links don't work after what I did, here's what I got:

    <PARAM name="FlashVars" Value="baseURL=#URLEncodedFormat(request.str_root_directory)#">

    and FlashVars="baseURL=#URLEncodedFormat(request.str_root_directory)#" in the emded tag,

    then in the flash i have:

    data_var = new LoadVars();
    data_var.path = this;
    data_var.onLoad = function(ok)
    {
          if (ok) {
                _root.so = SharedObject.getLocal("flashcookie");
                if(_root.so.data.rotator == undefined){
                      _root.so.data.rotator = 45;
                      _root.so.flush();
                }else{
                      _root.rotator_mc.gotoAndPlay(_root.so.data.rotator);
                }
                function gotolink(link)
                {
                      if(_root.rotator_mc._currentframe <= 45 || _root.rotator_mc._currentframe > 525){
                            _root.so.data.rotator = 45;
                      } else if(_root.rotator_mc._currentframe <= 165){
                            _root.so.data.rotator = 165;
                      } else if(_root.rotator_mc._currentframe <= 285){
                            _root.so.data.rotator = 285;
                      } else if(_root.rotator_mc._currentframe <= 405){
                            _root.so.data.rotator = 405;
                      } else if(_root.rotator_mc._currentframe <= 525){
                            _root.so.data.rotator = 525;
                      }
                      _root.so.flush();
                      getURL(link, "_self");
                }
          }
    };

    and on the links  I have

    on(release){
         _root.gotolink("_root.baseURL" + "dsp_school.cfm?int_school_id=14");    
    }

    I wish I could figure this stuff out easily, but don't use flash too often enough for it to stick, please help.  Thanks in advance.
    0
     
    LVL 27

    Expert Comment

    by:negatyve
    Wait, what are you trying to do?
    0
     

    Author Comment

    by:madasczik
    Trying to pass in a single flashvar and put the variable at the beginning of the URL.  I remember how to read in cfm files from previous examples that you gave me, thought it would be similar, guess not.  How do I add the variable to the beginning of my URL?
    0
     
    LVL 27

    Expert Comment

    by:negatyve
    <PARAM name="FlashVars" Value="baseURL=<cfoutput>#URLEncodedFormat(request.str_root_directory)#</cfoutput>">

    and

    on(release){
         _root.gotolink(_root.baseURL + "dsp_school.cfm?int_school_id=14");    
    }
    0
     

    Author Comment

    by:madasczik
    Cool!! I thought it would was something simple like that.  Had the extra quotes around _root.baseURL.  I usually put cfoutput around my entire page and double up on instances of # so that wasn't a problem.  My mistake was thinking that flashvars passed in were similar to loading full cfm files in, but that wasn't the case.  Thanks on getting me straightened out with that!!

    I'm wondering if the sharedOject is capable off detecting a refresh on the page as well.  Right now clicking on the images will move the timeline to the next section, but what if you were to click on a webpage link outside of flash or refresh the page, the flash clip will restart in the same section, given that not enough time hasn't passed for the timeline to get to the next section.  Is it possible to make it so that when I click on links outside of flash or refresh, the flash peice will move to the next timeline section?
    0
     
    LVL 27

    Expert Comment

    by:negatyve
    Yep, just do something like this:

    // ===============================================================
    data_var = new LoadVars();
    data_var.path = this;
    data_var.onLoad = function(ok)
    {
         if (ok) {
              _root.so = SharedObject.getLocal("flashcookie");
              if(_root.so.data.rotator == undefined){
                   _root.saveCookie(45);
              }else{
                   _root.rotator_mc.gotoAndPlay(_root.so.data.rotator);
              }
         }
    };
    function saveCookie(frame)
    {
          _root.so.data.rotator = frame;
          _root.so.flush();
    }
    // ===============================================================


    get back to your:

    // ===============================================================
    on(release){
          getURL("link.html", "_self");
    }
    // ===============================================================
    instead of using gotoLink, then add to given cuepoints of your rotator_mc clip the action to save the current frame.
    It is, on frame 45 of rotator mc:

    // ===============================================================
    _root.saveCookie(45);
    // ===============================================================


    on frame 165:

    // ===============================================================
    _root.saveCookie(285);
    // ===============================================================

    on frame 285:

    // ===============================================================
    _root.saveCookie(405);
    // ===============================================================

    and so on..
    0

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone. Privacy Policy Terms of Use

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.
    The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

    877 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now