/* * Copyright(c) 2008 the Spark project. * * Licensed under the Apache License, Version 2.0 (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.apache.org/licenses/LICENSE-2.0 * * 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. */ package { import flash.display.DisplayObject; import flash.display.Loader; import flash.display.MovieClip; import flash.events.ErrorEvent; import flash.events.Event; import flash.events.IOErrorEvent; import flash.events.ProgressEvent; import flash.events.SecurityErrorEvent; import flash.net.URLRequest; import flash.system.ApplicationDomain; import flash.system.LoaderContext; import flash.utils.getDefinitionByName; import jp.cohesion.preload.Message; /** * [Project Cohesion] * * プリローディング処理 * * @author $Author$ * @revision $Rev$ * @date $Date$ */ public class Preloader extends MovieClip { // コンストラクタ /////////////////////////////////////////////////////////////////// // Constructors // ///////////////////////////////////////////////////////////////////////////////////// /** * デフォルトの設定を用いてオブジェクトを構築するコンストラクタ */ public function Preloader(){ stop(); this.splash = new Message("Loading Cohesion Bootstrap... "); this.splash.x = 0; this.splash.y = 0; this.addChild(this.splash); addEventListener(Event.ENTER_FRAME, onEnterFrame); // Logd Runtime Shared Library var rslloader:Loader = new Loader(); var context:LoaderContext = new LoaderContext(); context.applicationDomain = ApplicationDomain.currentDomain; rslloader.contentLoaderInfo.addEventListener(Event.COMPLETE, loadConfigComplete); rslloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadConfigProgress); rslloader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, loadConfigFailure); rslloader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadConfigFailure); rslloader.load(new URLRequest(CONFIG_LIBRARY), context); } // 内部フィールド定義 /////////////////////////////////////////////////////////////// // Fields // ///////////////////////////////////////////////////////////////////////////////////// /** */ public static const CONFIG_LIBRARY:String = "CHConfig.swf"; /** */ private var rslLoaded:Boolean = false; /** */ private var splash:Message; // イベントハンドラ ///////////////////////////////////////////////////////////////// // Event Handler // ///////////////////////////////////////////////////////////////////////////////////// /** * * @param evt */ private function loadConfigProgress(evt:ProgressEvent):void { var percent:Number = (root.loaderInfo.bytesLoaded + evt.bytesLoaded) / (root.loaderInfo.bytesTotal + evt.bytesTotal); var p:int = percent * 100; this.splash.setText("Loading Cohesion Bootstrap... " + p + "%"); } /** * * @param evt */ private function loadConfigComplete(evt:Event):void { var loader:Loader = evt.target.loader as Loader; var md:DisplayObject = loader.content; loader.unload(); try { md["initialize"](stage); }catch (err:Error) { ; } rslLoaded = true; } /** * * @param evt */ protected function loadConfigFailure(evt:ErrorEvent):void { this.removeChild(this.splash); var message:Message = new Message("Failure loading configurations..."); message.x = 0; message.y = 0; this.addChild(message); } /** * ムービーが読み込まれている間中に処理されるEnterFrameイベント。 * * @param event イベント情報 */ public function onEnterFrame(event:Event):void { if (framesLoaded < totalFrames || !rslLoaded) { return; } //ロード完了 removeEventListener(Event.ENTER_FRAME, onEnterFrame); this.removeChild(this.splash); this.nextFrame(); initMainMovie(); } // インスタンスメソッド ///////////////////////////////////////////////////////////// // Instance Methods // ///////////////////////////////////////////////////////////////////////////////////// /** * メインムービークラスを初期化します。 * * * @param mainClassName */ public function initMainMovie():void { var mainClass:Class = Class( getDefinitionByName( "Main" ) ); if(mainClass){ var app:Object = new mainClass(); addChild(app as DisplayObject); } } } }