BrowserHistory Class | |
Constructor | |
new BrowserHistory(); | |
Arguments | |
vHomeItem | Required argument of any predefined data type representing the initial item to be added to the history list |
Methods | |
addItem() | Adds a new history item to the history list at its current index. |
Event Handlers | |
onHistoryChange() | Handler executed when browser history is changed via forward or backward browser buttons |
Description | |
Normally, pressing a browser's forward or backward navigation buttons on a Flash page will take you out of the movie. The BrowserHistory class allows developers to create a history list that can trigger actions based on the use of these buttons. When publishing to the WWW or testing in a browser locally, you will need the following files:
|
|
Example | |
A basic example of using the BrowserHistory class involves adding String values to the history list and outputting their values when you navigate with the browser buttons. The following example, illustrates this, and presumes that there are two textfields on stage (input and output) and one button (myAddItemBtn). // include the BrowserHistory class #include "BrowserHistory.as" // initiate a global instance of the class, passing the String argument "home" // "home" becomes the initial history item _global.myBH = new BrowserHistory("home"); // define custom function to call when browser button is used myBH.onHistoryChange = handleHistoryChange; // create function that defines what to do when browser button is used function handleHistoryChange(vItem){ // display the current history item in the output textfield output.text = "RECEIVED\n" + vItem; } // define onRelease handler for myAddItemBtn // (myAddItemBtn is a button that exists on stage) myAddItemBtn.onRelease = function(){ // add a history item to the history list (item is the string typed in the textfield instance input) _global.myBH.addItem(input.text); // display history item added in output output.text = "ADDED\n" + input.text; } |
|
|
|
BrowserHistory.addItem() Method | |
Syntax | |
myBH.addItem(vItem); | |
Arguments | |
vItem | required argument of any predefined data type representing the next item to be added to the history list |
Description | |
The addItem() method adds a new item to the history list at the history list's current index. This item can be any predefined type—Array, Number, Date, XML object, Boolean, etc. | |
Example | |
The following lines assign values to the history list: myBH.addItem( {a:1, b:2} ); myBH.addItem( new Array(1,2,3) ); myBH.addItem( true ); myBH.addItem( "sString" ); myBH.addItem( 2 ); |
|
|
|
BrowserHistory.onHistoryChange() Event Handler | |
Syntax | |
myBH.onHistoryChange(vItem); | |
Returns | |
vItem | a variable of any predefined data type containing the current item in the history list |
Description | |
The onHistoryChange() handler executes automatically whenever a forward or backward browser button is used, except, for the initialization scenario of the home item. The handler is not executed when initiating this item (coming to your page for the first time or coming to your page from a previous page). However, it is executed when returning to this item from the future if additional BrowserHistory items exist. The onHistoryChange() handler returns the current history item, which can be any predefined type—Array, Number, Date, XML object, Boolean, etc. You can create your own functions that act on on the returned history item, by assigning the onHistoryChange(), handler to a custom callback handler. |
|
Example | |
The following lines assigns a function to be called when a browser button has been pushed: var myBH = new BrowserHistory(myHomeItem); myBH.onHistoryChange = handleHistoryChange; function handleHistoryChange(vItem){ // Process what to do with history item here } |