Articles Archive
Articles Search
Director Wiki
 

A history question

February 23, 1998
by Pat McClellan

Dear Multimedia Handyman,

How can I create a history file similar to a Netscape history file that shows the pages (or in this case movies) that a user has visited? I'd like to enable them to click on an item on the history list and have them jump to that point.

Would it be difficult to enable them to bookmark a page (or movie) so that they could quickly return to that point.

TIA

Richard Boyle


Dear Richard

I've used these functions in many computer-based training programs that I've created. It's easy to do NEXT and BACK when the flow is linear, but with a non-linear structure to your program, you need to use a little lingo. One approach would be to create a navigation object to handle things, but I've never found the need to get into object-oriented programming for something this simple. (Plus, I needed to implement this function long before I had the slightest concept of what object-oriented programming was all about.)

So, here's the simple approach. You can adapt this to behaviors if you want, but these scripts will work fine in Director 5 as well.

Now, what we're going to do is commonly called "stacks". Think of it like one of those spring-loaded dispensers of cafeteria trays. You put each tray in the top, pushing the previous one down. Then, when the top one is removed, the others push back to the top. In our case, we're going to maintain 2 global lists: one is a list of the frames we've been to, and the other is a list of the movie names (in case you're jumping from movie to movie). If you will not be moving from movie to movie, then you can simplify the code by eliminating the movieList stuff.

So let's start with the startMovie handler


on startMovie
    global gMarkerList, gMovieList
    set gMarkerList = []
    -- initializes our list
    set gMovieList = []
    -- initializes our list
end

When the user clicks on a navigation option, BEFORE you do your "go to ...." command, you need to add the current marker and movie name to their respective lists.


on mouseUp
    global gMarkerList, gMovieList
    add gMarkerList, marker(0)  
    -- appends it to the list
    add gMovieList, the movie   
    -- appends it to the list
    go to whichFrame of movie whichMovie
end

Click on the buttons in the demo movie (except the BACK Button) to see how these global lists get built. Note that, since they're global variables, they persist when you jump from movie to movie.

You need <a href='http://www.macromedia.com/shockwave/'>ShockWave</a> 6 to view this movie!

Now that we have built a navigation "history", let's backtrack through that history. The BACK button needs to take us to the last marker (listed in gMarkerList) of the last movie (listed in gMovieList). Additionally, these last values in each list should be deleted. When all values have been deleted, then the user has moved back to the starting point and can't go any further. This is the script for the BACK button.

global gMarkerList, gMovieList
on mouseUp
  set x = count(gMarkerList)  
  -- same count as gMovieList
  if x = 0 then  
  -- check to see if we're at the beginning
    alert "Sorry, can't go back any further."
  else
    set whichMarker = getAt(gMarkerList, x)
    deleteAt(gMarkerList, x)
    set whichMovie = getAt(gMovieList, x)
    deleteAt(gMovieList, x)
    go to frame whichMarker of movie whichMovie
  end if
end
To implement a bookmark feature, you can use the same concepts of saving the marker and moviename in a list or field. If you want to save bookmarks for a later date, I recommend using FileIO to save your bookmark list as an external text file. You can also save a user's navigation history this way. Good luck with your project.
Patrick McClellan is Director Online's co-founder. Pat is Vice President, Managing Director for Jack Morton Worldwide, a global experiential marketing company. He is responsible for the San Francisco office, which helps major technology clients to develop marketing communications programs to reach enterprise and consumer audiences.

Copyright 1997-2017, Director Online. Article content copyright by respective authors.