root/Theme-1/t-matsuda/src/Root.as

Revision 17, 3.9 kB (checked in by t-matsuda, 11 months ago)

xml path changed

Line 
1 /**
2  * Theme-1 Root Class for Entacl Develop
3  *
4  * DESCRIPTION : ドキュメントクラス
5  *
6  * TODO:
7  *
8  * @author       t-matsuda <matsuda[at-mark]entacl.com>
9  * @version      0.0.1
10  *
11  * @see          http://www.entacl.com/
12  *
13  **/
14 package {
15         import flash.display.MovieClip;
16         import flash.display.Sprite;
17         import caurina.transitions.Tweener;
18         import transition.*;
19         import flash.utils.getDefinitionByName;
20         import br.com.stimuli.loading.BulkLoader;
21         import br.com.stimuli.loading.BulkErrorEvent;
22         import br.com.stimuli.loading.BulkProgressEvent;
23         import flash.text.TextFieldAutoSize;
24        
25         public class Root extends MovieClip {
26                 const XMLFILE:String = '/xml/theme-1/t-matsuda/theme.xml';
27                
28                 private var bulkInstance:BulkLoader;
29                 private var delay:uint = 3;
30                 private var tweenTime:uint = 4;
31                 private var num:int = -1;
32                
33                 public function Root() {
34                         init();
35                 }
36
37                 private function init():void {
38                         var item:Array = new Array();
39                         item.push( { id:'theme-xml', value:XMLFILE, type:'xml' } );
40                        
41                         setLoader('main', xmlLoaded, item);
42                         startLoader();
43                 }
44                
45                 private function xmlLoaded(event:BulkProgressEvent):void {
46                         removeLoading();
47                         ThemeXml.getInstance().setXML(bulkInstance.getXML('theme-xml'));
48                        
49                         nextTheme();
50                 }
51                
52                
53                 private function nextTheme():void {
54                         removeTheme();
55                        
56                         num++;
57                         if (ThemeXml.getInstance().getThemeCount() <= num) num = 0;
58                        
59                         var mc:MovieClip = new MovieClip();
60                         addChild(mc);
61                        
62                         var theme:ThemeText = new ThemeText();
63                         theme.themeInput.autoSize = TextFieldAutoSize.LEFT;
64                         theme.themeInput.text = ThemeXml.getInstance().getTheme(num);
65                         mc.addChild(theme);
66                        
67                         var lineMc:MovieClip = new MovieClip();
68                         mc.addChild(lineMc);
69                        
70                         var line1:LineGraphic = new LineGraphic(theme.width, theme.height / 2);
71                         lineMc.addChild(line1);
72                
73                         var line2:LineGraphic = new LineGraphic(theme.width, theme.height / 2);
74                         line2.y = theme.height / 2;
75                         lineMc.addChild(line2);
76                        
77                         theme.cacheAsBitmap = true;
78                        
79                         lineMc.mask = theme;
80                        
81                         //change transition
82                         new PixelDissolveIn(mc, { duration:delay } );
83                        
84                         Tweener.addTween(theme, {
85                                 x: -theme.width,
86                                 delay: delay,
87                                 time: tweenTime,
88                                 transition : "linear",
89                                 onStart: function() {
90                                         theme.cacheAsBitmap = false;
91                                 },
92                                 onComplete: function () {
93                                         nextTheme();
94                                 }
95                         });
96                 }
97                
98                 private function removeTheme():void {
99                         var trash:Array = new Array();
100                         for (var i:uint = 0; i < numChildren; i++ ) {
101                                 trash.push(getChildAt(i));
102                         }
103                        
104                         for each (var item in trash) {
105                                 removeChild(item);
106                         }
107                 }
108                
109                
110                 private function setLoader(name:String, complete:Function, add:Array):void {
111                         bulkInstance = new BulkLoader(name);
112                         bulkInstance.addEventListener(BulkLoader.ERROR, onError);
113                         bulkInstance.addEventListener(BulkLoader.PROGRESS, onProgress);
114                         bulkInstance.addEventListener(BulkLoader.COMPLETE, complete);
115                        
116                         for each (var item:Object in add) {
117                                 bulkInstance.add(item.value, {id:item.id, type:item.type});
118                         }
119                 }
120                
121                 private function startLoader():void {
122                         bulkInstance.start();
123                 }
124                
125                 private function onError(event:BulkErrorEvent):void {
126                         for each (var err:String in event.errors) {
127                                 trace('error message:' + err);
128                         }
129                 }
130                
131                 private function onProgress(event:BulkProgressEvent):void {
132                         setLoading();
133                 }
134                
135                 private function setLoading():void {
136                         var loadingMc:Loading = new Loading();
137                         loadingMc.x = stage.stageWidth / 2;
138                         loadingMc.y = stage.stageHeight / 2;
139                         addChild(loadingMc);
140                 }
141                
142                 private function removeLoading():void {
143                         var trash:Array = new Array();
144                         for (var i:int = 0; i < numChildren; i++ ) {
145                                 if (getChildAt(i) is Loading) {
146                                         trash.push(getChildAt(i));
147                                 }
148                         }
149                        
150                         for each (var item:Loading in trash) {
151                                 removeChild(item);
152                         }
153                 }
154         }
155        
156 }
Note: See TracBrowser for help on using the browser.