root/as3/Cohesion/framework/trunk/SystemCommands/SystemCommand.as

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

・ガジェットの重なり順変更方法を swapChildrenAt から setChildIndex に変更 (GadgetManager?.as)
CohesionMovieClip?に callFocus メソッド追加(CohesionMovieClip?.as)
SystemCommand?にバグあり。モジュールコマンド用メソッドの引数は可変長にしちゃだめ。必ずArrayで受け取ること。(SystemCommand?.as)

  • 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.events.ErrorEvent;
19         import flash.events.Event;
20         import flash.events.IOErrorEvent;
21         import flash.events.SecurityErrorEvent;
22         import flash.utils.Dictionary;
23         import jp.cohesion.common.Gadget;
24         import jp.cohesion.common.module.BaseModule;
25         import jp.cohesion.common.IKernel;
26         import jp.cohesion.common.module.events.ServerEvent;
27         import jp.cohesion.common.module.MovieLoaderGadget;
28        
29         /* == [Project Cohesion] =================================================== */
30        
31         /**
32          * システムコマンド包括クラス
33          *
34          * @author              $Author$
35          * @revision    $Rev$
36          * @date                $Date$
37          */
38         public class SystemCommand extends BaseModule {
39                 // コンストラクタ ///////////////////////////////////////////////////////////////////
40                 //                                                                    Constructors //
41                 /////////////////////////////////////////////////////////////////////////////////////
42
43                 /**
44                  *      デフォルトの設定を用いてオブジェクトを構築するコンストラクタ
45                  */
46                 public function SystemCommand(){
47                         super();
48                 }
49                
50                 private var movies:Dictionary = new Dictionary();
51                
52                 public static const EVENT_PREFIX:String = "chn:system:";
53                
54                 // インスタンスメソッド /////////////////////////////////////////////////////////////
55                 //                                                                Instance Methods //
56                 /////////////////////////////////////////////////////////////////////////////////////
57                
58                 /**
59                  *
60                  * @param       kernel
61                  */
62                 public override function initialize(kernel:IKernel):void {
63                         super.initialize(kernel);
64                        
65                         kernel.addEventListener(EVENT_PREFIX + "LoadMovie", onLoadMovie);
66                 }
67                
68                 /**
69                  *
70                  * @param       args
71                  * @return
72                  */
73                 public function loadMovie(args:Array):Object {
74                         if (args === null || args.length < 1) { return null; }
75                        
76                         var movie:String = args[0];
77                         var pos:String = null;
78                         if (args.length > 1) { pos = args[1]; }
79                        
80                         startLoadingMovie(movie, pos);
81                         return null;
82                 }
83                
84                 /**
85                  *
86                  * @param       args
87                  * @return
88                  */
89                 public function removeMovie(args:Array):Object {
90                         if (args != null && args.length > 0) {
91                                 var name:String = args[0];
92                                 if (name == null) { return null; }
93                                
94                                 var prefix:String = name.substr(0, MovieLoaderGadget.GADGETNAME_PREFIX.length);
95                                 if (prefix != MovieLoaderGadget.GADGETNAME_PREFIX) { name = MovieLoaderGadget.GADGETNAME_PREFIX + name; }
96                                 removeMovieGadget(name);
97                         }
98                         return null;
99                 }
100                
101                 // イベントハンドラ /////////////////////////////////////////////////////////////////
102                 //                                                                   Event Handler //
103                 /////////////////////////////////////////////////////////////////////////////////////
104                
105                 /**
106                  *
107                  * @param       evt
108                  */
109                 public function onLoadMovie(evt:ServerEvent):void {
110                         if (evt.data.movie != undefined) {
111                                 startLoadingMovie(evt.data.movie, evt.data.movie.@position);
112                         }
113                 }
114                
115                 // 内部メソッド /////////////////////////////////////////////////////////////////////
116                 //                                                                 Private Methods //
117                 /////////////////////////////////////////////////////////////////////////////////////
118                
119                 /**
120                  *
121                  * @param       movie
122                  * @param       position
123                  */
124                 public function startLoadingMovie(movie:String, position:String = null):void {
125                         var gadget:MovieLoaderGadget = new MovieLoaderGadget(SYSTEM_COMMAND_MODULE, kernel);
126                         gadget.url = movie;
127                         if (position) { gadget.position = position; }
128                        
129                         removeMovieGadget(gadget.gadgetName);
130                        
131                         gadget.addEventListener(Event.COMPLETE,                    loadComplete);
132                         gadget.addEventListener(IOErrorEvent.IO_ERROR,             loadFailure);
133                         gadget.addEventListener(SecurityErrorEvent.SECURITY_ERROR, loadFailure);
134                         gadget.load();
135                 }
136                 /**
137                  *
138                  * @param       evt
139                  */
140                 private function loadFailure(evt:ErrorEvent):void {
141                         var gadget:MovieLoaderGadget = evt.target as MovieLoaderGadget;
142                         this.kernel.showTemporaryMessage("ムービー\"" + gadget.url + "\"の読み込みに失敗しました。");
143                 }
144                 /**
145                  *
146                  * @param       evt
147                  */
148                 private function loadComplete(evt:Event):void {
149                         var gadget:MovieLoaderGadget = evt.target as MovieLoaderGadget;
150                         gadget.removeEventListener(Event.COMPLETE, loadComplete);
151                        
152                         this.movies[gadget.gadgetName] = gadget;
153                 }
154                
155                 /**
156                  *
157                  * @param       url
158                  */
159                 public function removeMovieByURL(url:String):void {
160                         removeMovieGadget(MovieLoaderGadget.GADGETNAME_PREFIX + url);
161                 }
162                
163                 /**
164                  *
165                  * @param       name
166                  */
167                 public function removeMovieGadget(name:String):void {
168                         if (name == null) { return; }
169                         if (movies[name] == undefined) { return; }
170                        
171                         var mv:Gadget = movies[name];
172                         try {
173                                 if (mv.parent != null) {
174                                         kernel.removeGadget(mv);
175                                 }
176                         }catch (err:Error) { trace(err); }
177                         delete movies[name];
178                 }
179
180         }
181
182 }
Note: リポジトリブラウザについてのヘルプは TracBrowser を参照してください。