Director News
Director Web Sites
Mailing Lists
News Groups
Project Examples
Useful Web Sites

Don't miss these
PopUp Menu
SM scroll slowdown
DM Stars Field Effect
System Tools
Follow me
bubbleSortForStrings AND bubbleSortForStringLists
CD Door Close, Open - MCI
Trim Function
Button With Rollover Effect



Article A Simple Back Button

Added on 7/19/1999


D7 D8 Mac PC Shockwave


Author: MediaMacros (website)

My projector plays a movie that is like an index. In it users can click to go to a section, move forward, etc. How can I make a back button (similar to a web browser) so they can retrace their steps?

This process involves 2 basic components.  The first is a simple
list.  We want to track where the person goes, but not every frame.  We could
set a script that triggers every frame and checks the last marker, but that hogs
unnecessary processor power.  For this example we will use a simple frame script.
  The nice part of this approach is that you only add a "back state" on the
frames you drop the script on. 

To generate our list of digital footprints we can retrace, we can start
with a simple call to a global variable and add the current frame to the list.  
Something like add gBackList, the frame.  This will add to the global list
gBackList with the current frame number.  Simple enough.  Well how do we go back
a frame?  If we went to the last entry in the list we would end up at the current
frame or section, so we need to look one back, at the next-to-last frame in the
list.  Further more we need to also remove the last entry from the list when jumping
back, as it is no longer in our linear path.

To track this we use another global variable.  In this example it is
called gBack.  If gBack is true then the last navigation method was the back button.
  If it is false, we are progressing in a forward direction.  The back button
would look something like this...

global gBack, gBackList
on mouseUp me
howMany = gBackList.count
if howMany > 1 then --There is a back state
gBack = true
go gBackList[howMany - 1]
end if

The if statement keeps us from getting errors if the user is at the
starting point of the back list.  (No where else to back track to.)  Now that we
have established that the back button has been clicked and we have jumped back to the
correct frame we need a frame script.  Using the same script we can remove unneeded
entries when the back button is used, as well as add new ones when we enter the frame via
normal navigation.

global gBack, gBackList
on enterFrame me
if gBack = void then gBack = false
if gBackList = void then gBackList = []
howMany = gBackList.count
if gBack = true then --came from back button
gBack = false
deleteAt gBackList, howMany
if howMany > 0 then
if gBackList[howMany] <> the frame then
--prevents the same frame from being added twice in a row
add gBackList, the frame
end if
add gBackList, the frame
end if
end if

Now, each time the user enters the frame the script checks to see how they
got there and either adds or removes an entry from the list.  The extra if statement
prevents the same frame from being added twice in a row.  We also need to check the
variables and make sure that if they have never been used (if their value is
"void") then we set them to their default states.  It is also a good idea
to set theses in your startMovie script to clear them out during authoring so you don't
start with the back list of a previous session while testing.

If you want to customize this one you could make a next button list as
well, or set different rollover and default graphic states for the button depending on if
there are items in the back list or not, or add functionality for different movies to be
tracked in the list as well.

Here is an example of the code in action...

You need <A HREF = ''>ShockWave</A> to view this movie.

As usual, you can also find all of these behaviors/scripts in the behavior database.



36 South Court Sq
Suite 300
Newnan, GA 30263

Send e-mail