[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

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.


0
madasczik
Asked:
madasczik
  • 4
  • 4
1 Solution
 
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
 
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
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

 
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

Featured Post

Receive 1:1 tech help

Solve your biggest tech problems alongside global tech experts with 1:1 help.

  • 4
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now