root/as3/Cohesion/framework/trunk/Bootstrap/Preloader.as

リビジョン 345, 5.3 kB (コミッタ: amoi, コミット時期: 4 年 前)

Cohesion Frameworkを登録します。

  • svn:keywords 属性の設定値: Id Date Author Rev
Line 
1 /*
2  * Copyright(c) 2008 the Spark project.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
13  * either express or implied. See the License for the specific language
14  * governing permissions and limitations under the License.
15  */
16
17 package {
18         import flash.display.DisplayObject;
19         import flash.display.Loader;
20         import flash.display.MovieClip;
21         import flash.events.ErrorEvent;
22         import flash.events.Event;
23         import flash.events.IOErrorEvent;
24         import flash.events.ProgressEvent;
25         import flash.events.SecurityErrorEvent;
26         import flash.net.URLRequest;
27         import flash.system.ApplicationDomain;
28         import flash.system.LoaderContext;
29         import flash.utils.getDefinitionByName;
30         import jp.cohesion.preload.Message;
31        
32         /**
33          *      [Project Cohesion]
34          *     
35          *      プリローディング処理
36          *
37          * @author              $Author$
38          * @revision    $Rev$
39          * @date                $Date$
40          */
41         public class Preloader extends MovieClip {
42                 // コンストラクタ ///////////////////////////////////////////////////////////////////
43                 //                                                                    Constructors //
44                 /////////////////////////////////////////////////////////////////////////////////////
45
46                 /**
47                  *      デフォルトの設定を用いてオブジェクトを構築するコンストラクタ
48                  */
49                 public function Preloader(){
50                         stop();
51                        
52                         this.splash = new Message("Loading Cohesion Bootstrap...       ");
53                         this.splash.x = 0;
54                         this.splash.y = 0;
55                         this.addChild(this.splash);
56                        
57                         addEventListener(Event.ENTER_FRAME, onEnterFrame);
58                        
59                         // Logd Runtime Shared Library
60                         var rslloader:Loader = new Loader();
61                         var context:LoaderContext = new LoaderContext();
62                         context.applicationDomain = ApplicationDomain.currentDomain;
63                         rslloader.contentLoaderInfo.addEventListener(Event.COMPLETE,                    loadConfigComplete);
64                         rslloader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,            loadConfigProgress);
65                         rslloader.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR,             loadConfigFailure);
66                         rslloader.contentLoaderInfo.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadConfigFailure);
67                         rslloader.load(new URLRequest(CONFIG_LIBRARY), context);
68                 }
69
70                 // 内部フィールド定義 ///////////////////////////////////////////////////////////////
71                 //                                                                          Fields //
72                 /////////////////////////////////////////////////////////////////////////////////////
73                
74                 /**  */
75                 public static const CONFIG_LIBRARY:String = "CHConfig.swf";
76                
77                 /**  */
78                 private var rslLoaded:Boolean = false;
79                
80                 /**  */
81                 private var splash:Message;
82
83                 // イベントハンドラ /////////////////////////////////////////////////////////////////
84                 //                                                                   Event Handler //
85                 /////////////////////////////////////////////////////////////////////////////////////
86                
87                 /**
88                  *
89                  * @param       evt
90                  */
91                 private function loadConfigProgress(evt:ProgressEvent):void {
92                         var percent:Number = (root.loaderInfo.bytesLoaded + evt.bytesLoaded) / (root.loaderInfo.bytesTotal + evt.bytesTotal);
93                         var p:int = percent * 100;
94                        
95                         this.splash.setText("Loading Cohesion Bootstrap... " + p + "%");
96                 }
97                
98                 /**
99                  *
100                  * @param       evt
101                  */
102                 private function loadConfigComplete(evt:Event):void {
103                         var loader:Loader = evt.target.loader as Loader;
104                         var md:DisplayObject = loader.content;
105                         loader.unload();
106                        
107                         try {
108                                 md["initialize"](stage);
109                         }catch (err:Error) { ;  }
110                        
111                         rslLoaded = true;
112                 }
113                
114                 /**
115                  *
116                  * @param       evt
117                  */
118                 protected function loadConfigFailure(evt:ErrorEvent):void {
119                         this.removeChild(this.splash);
120                        
121                         var message:Message = new Message("Failure loading configurations...");
122                         message.x = 0;
123                         message.y = 0;
124                         this.addChild(message);
125                 }
126                
127                 /**
128                  *      ムービーが読み込まれている間中に処理されるEnterFrameイベント。
129                  *     
130                  *      @param event イベント情報
131                  */
132                 public function onEnterFrame(event:Event):void {
133                         if (framesLoaded < totalFrames || !rslLoaded) { return; }
134                        
135                         //ロード完了
136                         removeEventListener(Event.ENTER_FRAME, onEnterFrame);
137                        
138                         this.removeChild(this.splash);
139                         this.nextFrame();
140                        
141                         initMainMovie();
142                 }
143                
144                 // インスタンスメソッド /////////////////////////////////////////////////////////////
145                 //                                                                Instance Methods //
146                 /////////////////////////////////////////////////////////////////////////////////////
147                
148                 /**
149                  *      メインムービークラスを初期化します。
150                  *     
151                  *     
152                  *      @param mainClassName
153                  */
154                 public function initMainMovie():void {
155                         var mainClass:Class = Class( getDefinitionByName( "Main" ) );
156                         if(mainClass){
157                                 var app:Object = new mainClass();
158                                 addChild(app as DisplayObject);
159                         }
160                 }
161
162         }
163
164 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。