Have Flash Remember Frame For When Page Reloads

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.


madasczikAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

negatyveCommented:
(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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
madasczikAuthor Commented:
Simply amazing code!!
0
madasczikAuthor Commented:
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
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

negatyveCommented:
Wait, what are you trying to do?
0
madasczikAuthor Commented:
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
negatyveCommented:
<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
madasczikAuthor Commented:
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
negatyveCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.