The AF FS Command JavaScript Library Movie Reference Information

This is a continuation of the Movie Reference Information page and requires that you have read and understood that page.

Working with windows

In order to create a reference to a movie in another window, the window must have been created using the popupMaker function. As with movie references, window references are stored in an array and the window number used to create the window via popupMaker should not be used to create additional windows.

The window number used to create the window via popupMaker is the number that must be sent as the window number in all functions that create a movie reference for a movie in another window.

Do not use 0 as the window number when creating a window via popupMaker
To allow the created window to make references to movies in the main window, the window reference that corresponds to the number 0 is automatically set to equal the window that created the popup window.

Setting References
There are several functions for setting references to movies in another window. Unless there are frames in the windows, you must use either setWindowRef or setLayerWindowRef to create the movie reference(s).

If there are frames in any of the other windows, you must use either setWindowFrameRef or setLayerWindowFrameRef to create the movie references for movies in the frames. It is also strongly recommended that you read Setting Movie References in Multiple Frames.

To allow commands to be sent back and forth between windows, at least one document in each window must have the script library loaded into it.

The following examples and information pertain only to windows that do not involve frames. To work with a combination of frames and windows, you will need to fully understand this document and Setting Movie References in Multiple Frames. You will need to combine the techniques in both documents together in a manner that best suits your exact situation.

In this example, there is the main window (the one that the user surfed to) and a window created with popupMaker with the window reference number of 1.

To set a movie reference inthe main window to a movie in the window with the reference number of 1, you would send 1 as the window number in the movie reference creation function.

Do not confuse the movie reference number with the window reference number. Although the two reference numbers can be the same, they are referring to two different arrays. The window array holds only the references to the actual windows and not any of their content. The movie array holds a direct reference to an individual movie that can be in the same document or a different frame or window.

Back to the example
setWindowRef(1,'myMovie0',12)
when called from the main window, this creates a reference in the main window to the movie named myMovie0 in the window with the window reference number of 1. The movie reference created has the movie reference number of 12. For all functions that act upon a movie called in the main window, you would send 12 to the function if you want it to be enacted upon the movie created with this reference in the window with the reference number of 1.

playMovie(12)
when called from the script in the main window will cause the move named myMovie0 to play in the popup window.

To make a reference to a movie in the main movie from the popup window, use the window reference number of 0 to create the movie reference.
setWindowRef(0,'myMovie1',12)
this creates a reference in the popup window to the movie named myMovie1 in the main window. You may have noticed that this movie also has the movie reference number of 12. This was done as an example that a movie reference created by the script in one window is not automatically available to the script in another window.

So, calling playMovie(12) in the popup window will now play a movie named myMovie1 in the main window, and calling playMovie(12) from the main movie will still play the movie named myMovie0 in the popup.

The tricky part
Movies in a window must exist before they can have a reference set to them in JavaScript. This means that it is better to have each movie or onLoad event script create the movie reference for the movie(s) on that page. Otherwise, you must at least create a method for pausing between the creation of the window via the popupMaker function and the call to create the movie reference to a movie in the popup window.

The most simple method for doing this would be to create a function similar to the onload event covered in the Movie Reference Information page. The function would reside in the script in the main window, but be called via the onLoad event of the popup window.

Still assuming that the popup window was created with the window reference of 1, and that there are no frames involved, the script in the main window would look something like this:
function myLoader1()
{
setWindowRef(1,'myMovie4',5);
setWindowRef(1,'myMovie5',6);
setWindowRef(1,'myMovie6',7);
}
then, set the onLoad event of the BODY tag of the popup window to call this function in the main window:
onLoad="w[0].myLoader1()"
w is the name of the array that holds the movie references. The index number 0 of the window array is set to equal the window that created the popup window as soon as the popup window's script is read into the browser.

This onLoad event action will call the function in the main window and create the three movie references in the main window. These movie references will not exist to the popup window.

If you need to create one or more movie references in the popup window as well as in the main window, you will need to create a function to handle the onLoad event of the popup window document.
Script in the main window:
function myLoader()
{
setMovieRef('myMovie1',0);
setMovieRef('myMovie2',1);
setMovieRef('myMovie3',2);
setMovieRef('myMovie4',3);
setMovieRef('myMovie5',4);
}

function myLoader1()
{
setWindowRef(1,'myMovie4',5);
setWindowRef(1,'myMovie5',6);
setWindowRef(1,'myMovie6',7);
}
Script in the popup window:
function myLoader()
{
setMovieRef('myMovie4',0);
setMovieRef('myMovie5',1);
setMovieRef('myMovie6',2);
setWindowRef(0,'myMovie1',3);
w[0].myLoader1(); }
then, make the onLoad events of the popup window and the main window a call to the the myLoader function that is on that page:
onLoad="myLoader()"

When the main window loads, it will execute its onLoad event and create the references for the five movies that reside on that page. The myLoader1() function will not be executed at that time. Later, when popup window 1 is created, its load event will first create the references to the three movies that reside in the popup and a reference to the movie named myMovie1 in the main window for use within the popup. Then, it will invoke the myLoader1() function on the main page. The myLoader1() function will create references to the three movies in the popup for use by the main window.

As you can see in this example, to make a call to myMovie6 from the main window, you would use the movie reference number of 7. But, to make a call to this same movie from the popup window, you would use the movie reference number of 2.

To make a call to myMovie1 from within the main window, the reference number would be 0. To make a call to the same movie from the popup, the reference would be 3.

To get a quick view of some of the things that are possible with this library, see the examples.

To get the library, see the download area.


Examples Download Reference

Copyright©2000, AshzFall. All Rights Reserved.
Macromedia and Flash are trademarks of Macromedia, Inc.