/** * "History" -- a wrapper class for unfocus's HistoryKeeper. We use flash, and unfocus is * cool. The FlashSuite is way too complicated, especially since ExternalInterface is on * the scene. So, using ExternalInterface, and HistoryKeeper, we now have a super clean, * super easy to use Flash-Based-History-System. * * Thanks unfocus-history-keeper Team! * * Requirements: * unFocusHistory-p.js -- or any derivative of unfocus HistoryKeeper * History.js -- the javascript class file * History.as -- this actionscript file * * Issues: * safari dosent work. bookmarking works fine, but setting unFocus.History.addHistory(); * does not register history states when it comes from flash. */ class thetainteractive.utilities.History { /** * public static initialize * this method calls the start method. it starts up the history class in * both AS and JS. If a bookmarked hash is in the URI or the browser, it * will default to that when it starts up, otherwise, it will use the hash * you specify as the hash parameter * * @param hash:String * the starting hash key you want to start the site with. will be * over-ridden by the browser URI if there is a bookmark. * * @see #start */ public static function initialize (hash):Void { getInstance().start(hash); } /** * public static setHistory * sets a history state in both AS and JS. will only broadcast to subscribers * if there is a change in the hash. duplicate hash calls will be ignored. * * @param hash:String * the hash to set as the current hash * * @see #setState */ public static function setHistory (hash):Void { getInstance().setState(hash); } /** * public static getHistory * sends back the current hash that the class is working with * * @return:String * the current hash */ public static function getHistory ():String { return HASH; } /** * public static addListener * add a subscriber to the "history" event. any time the current history * state changes, the listener will be notified of the new hash. it is up * to this/these listeners to parse the hash and render ths scene. * * @param obj:Object * the object that will recieve "history" events * * @see AsBroadcaster */ public static function addListener (obj:Object):Void { getInstance().addListener(obj); } /** * public static removeListener * remove a subscriber to the "history" event. * * @param obj:Object * the object to remove * * @see AsBroadcaster */ public static function removeListener (obj:Object):Void { getInstance().removeListener(obj); } /** * Constructor * * use AsBroadcaster to do listeners * resgister a callback for the javascript event */ function History () { AsBroadcaster.initialize(this); flash.external.ExternalInterface.addCallback("thetainteractive_utilities_History_setHistory", this, setState); } private static var _instance:History; private static var HASH:String; private var broadcastMessage:Function; /** * private start * we check to see if the getHistory state has been set. if so, then we * use that, otherwise, use the hash argument supplied. then setState * based on the results. * * @see #initialize */ private function start (hash):Void { var result = flash.external.ExternalInterface.call("thetainteractive.utilities.History.getHistory"); if (result=="null"||result==""||result==null||result==undefined) result = hash; setState(result); } /** * private setState * if the incoming hash is different than our existing hash, we're in business. * if so, save for the next call, broadcast to our listsners that the state * has changed, and then tell javascript about it as well. javascript will * immediatedly try and re-set this method, but because we are checking for * inequality, it will basically die silently. * * @see #setHistory */ private function setState (hash):Void { if (HASH!=hash) { HASH = hash; broadcastMessage("history", HASH); flash.external.ExternalInterface.call("thetainteractive.utilities.History.setHistory", HASH); } } /** * private static getInstance * this basically makes use this class remains a Singleton class. all public * static methods use this first, so only one instance gets created. * * @returns:History * the Singleton instance of the class */ private static function getInstance ():History { if (!_instance) _instance = new History(); return _instance; } }