/*----------------------------------------------------------------------------- The contents of this file are subject to the Mozilla Public License Version 1.1 (the "License"); you may not use this file except in compliance with the License.You may obtain a copy of the License at http://www.mozilla.org/MPL/MPL-1.1.html Software distributed under the License is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for the specific language governing rights and limitations under the License. The Original Code is Fever Framework code. The Initial Developer of the Original Code is Romain Ecarnot. Portions created by Initial Developer are Copyright (C) 2006 the Initial Developer. All Rights Reserved. Contributor(s): Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. -----------------------------------------------------------------------------*/ import com.bourre.data.libs.ILibListener; import com.bourre.data.libs.LibEvent; import fever.core.CoreApplicationLoader; import fever.core.FeverRoot; import fever.install.InstallerUI; import fever.install.InstallUIStrategy; /** * ExpressInstall class definition and application preloading system. * *

Use this class to invoke the Adobe Flash Player Express Install functionality. * *

This class is intended for use with the SWFObject embed script.
* You can download SWFObject and this class here: http://blog.deconcept.com/swfobject/ * *

Take a look at {@link fever.install.DefaultInstaller} to see how to use it with MTASC. * * @see fever.install.DefaultInstaller * @see fever.install.InstallerUI * * @author Romain Ecarnot */ class fever.install.FeverInstaller extends MovieClip implements ILibListener { //------------------------------------------------------------------------- // Private implementation //------------------------------------------------------------------------- private static var _instance : FeverInstaller; private var _updater : MovieClip; private var _hold : MovieClip; private var _lib : CoreApplicationLoader; private var _ui : InstallUIStrategy; //------------------------------------------------------------------------- // Public API //------------------------------------------------------------------------- /** * Starts preloading system */ public static function load( ui : InstallUIStrategy ) : Void { FeverInstaller.getInstance( ui ); } /** * Triggred by {@link fever.core.CoreApplicationLoader} lib. */ public function onLoadInit( e : LibEvent ) : Void { _release(); } /** * Triggred by {@link fever.core.CoreApplicationLoader} lib. */ public function onLoadProgress( e : LibEvent ) : Void { _ui.onProgress( e ); } /** * Triggred by {@link fever.core.CoreApplicationLoader} lib. */ public function onTimeOut( e : LibEvent ) : Void { _ui.onTimeOut( e ); } //------------------------------------------------------------------------- // Private implementation //------------------------------------------------------------------------- /** * Returns unique instance. */ private static function getInstance( ui : InstallUIStrategy ) : FeverInstaller { if ( !_instance ) _instance = new FeverInstaller( ui ); return _instance; } /** * Constructor. */ private function FeverInstaller( ui : InstallUIStrategy ) { if ( _root.MMplayerType == undefined ) _loadApplication( _root, ui ); else _loadUpdater(); } /** * Loads your application * *

Assimilating _root */ private function _loadApplication( target, ui : InstallUIStrategy ) : Void { Stage.scaleMode = 'NoScale'; Stage.align = 'TL'; target.__proto__ = this.__proto__; target.__constructor__ = FeverInstaller; this = target; var appName : String = _url.substring( _url.lastIndexOf( '/' ) + 1, _url.lastIndexOf( '_installer.swf' ) ) + '.swf'; _lib = new CoreApplicationLoader( this, 1, true ); _lib.addListener( this ); _lib.setTimeOut( 5000 ); _lib.setAntiCache( true ); _lib.setURL( appName ); FeverRoot.LEVEL = _lib.getContainerLevel(); _buildProgressUI( ui ); _lib.load( _lib.getURL() ); } /** * Loads Adobe updater * * _root is not assimilated. */ private function _loadUpdater():Void { System.security.allowDomain( 'fpdownload.macromedia.com' ); _updater = _root.createEmptyMovieClip( 'expressInstallHolder', 100000000 ); _updater.installStatus = this.installStatus; _hold = _updater.createEmptyMovieClip( 'hold', 1 ); _updater.onEnterFrame = function() { if ( typeof this.hold.startUpdate == 'function' ) { FeverInstaller.getInstance()._loadInit(); delete this.onEnterFrame; } }; var cacheBuster = Math.random(); _hold.loadMovie( 'http://fpdownload.macromedia.com/pub/flashplayer/update/current/swf/autoUpdater.swf?' + cacheBuster); } /** * Retreives Express install FlashVars */ private function _loadInit() { _hold.redirectURL = _root.MMredirectURL; _hold.MMplayerType = _root.MMplayerType; _hold.MMdoctitle = _root.MMdoctitle; _hold.startUpdate(); } /** * Triggered by the uploader. */ private function installStatus( statusValue : String ) : Void { _hold.removeMovieClip(); _updater.removeMovieClip(); if ( statusValue == 'Download.Complete' ) { getURL("javascript:window.opener=self;self.close()"); } else if ( statusValue == 'Download.Cancelled' ) { getURL("javascript:alert('This content requires a more recent version of the Macromedia Flash Player.')"); } else if ( statusValue == 'Download.Failed' ) { getURL( "javascript:alert('There was an error in downloading the Flash Player update. Please try again later, or visit macrmedia.com to download the latest version of the Flash plugin.')" ); } } /** * Builds a simple UI for listening preloading state. */ private function _buildProgressUI( ui : InstallUIStrategy ) : Void { _ui = ( !ui ) ? new InstallerUI( 0x68808c ) : ui; _ui.create( this ); } /** * Loading is complete.
* Removes Stage listener
* Removes preloading library listener too. * *

Don't use GraphicLib.release() method as lib target is used * by the FeverRoot class to retreive correct application root target. */ private function _release() : Void { _lib.removeListener( this ); _ui.dispose(); _ui = null; } }