Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Have Flash Remember Frame For When Page Reloads

Posted on 2004-10-27
8
Medium Priority
?
200 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
Comment
Question by:madasczik
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 27

Accepted Solution

by:
negatyve earned 2000 total points
ID: 12427768
(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
ID: 12428005
Simply amazing code!!
0
 

Author Comment

by:madasczik
ID: 12428641
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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 27

Expert Comment

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

Author Comment

by:madasczik
ID: 12433984
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
ID: 12434541
<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
ID: 12437263
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
ID: 12442103
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.

610 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