AS3で外部SWFの読み込みとロード状況の監視をする「SWFLoader」クラス

ActionScript3.0で外部SWFの読み込みとロード状況の監視をする「SWFLoader」クラスを作成しました。

SWFファイルを読み込むターゲットと、SWFファイルへのパスを指定して使用します。

外部ファイルを読み込むターゲットと、外部ファイルへのパスを指定して使用します。ロード開始時と完了時に実行する関数を指定したり、ローディング時とロード完了時のフラグ等を外部から取得することが可能です。

外部ファイル・プログレスバーのアルファ値(初期値)や、ロード開始するまでの待機時間(秒数)を指定できます。また、プログレスバーのサイズ/色/フィルタ設定、パーセントテキストのフォント等も指定可能です。

ファイル

使用方法

  • main.swfを読み込み
1
2
var myLoader:MovieClip = new SWFLoader();
myLoader.load(this, "main.swf");
  • exsample.jpgを _mcへ読み込み
1
2
3
4
5
var _mc:MovieClip = new MovieClip();
addChild(_mc);

var myLoader:MovieClip = new SWFLoader();
myLoader.load(_mc, "exsample.jpg");
  • main.swfを読み込み、ロード開始時に onLoadFunction関数を実行する
1
2
3
4
5
var onLoadFunction:Function = function(){
  trace("外部ファイルのロードが開始されました")
};
var myLoader:MovieClip = new SWFLoader();
myLoader.load(this, "main.swf", onLoadFunction);
  • main.swfを読み込み、ロード完了時に onCompleteFunction関数を実行する
1
2
3
4
5
var onCompleteFunction:Function = function(){
  trace("外部ファイルのロードが完了しました")
};
var myLoader:MovieClip = new SWFLoader();
myLoader.load(this, "main.swf", null, onCompleteFunction);
  • main.swfとプログレスバーのアルファ(初期値)を 0に指定してロードを開始する
1
2
3
4
5
6
7
8
9
10
11
12
var childDefAlpha:Number = 0;
var loadProgressDefAlpha:Number = 0;

var myLoader:MovieClip = new SWFLoader();
myLoader.load(
  this,
  "main.swf",
  onLoadFunction,
  onCompleteFunction,
  childDefAlpha,
  loadProgressDefAlpha
);
  • 2秒後に main.swfの読み込みを開始する
1
2
3
4
5
6
7
8
9
10
11
12
var delaySecond:Number = 2;

var myLoader:MovieClip = new SWFLoader();
myLoader.load(
  this,
  "main.swf",
  onLoadFunction,
  onCompleteFunction,
  childDefAlpha,
  loadProgressDefAlpha,
  delaySecond
);
  • ローディングバーを表示しない
1
2
3
4
5
6
7
8
9
10
11
12
13
var isLoadProgressBar:Boolean = false;

var myLoader:MovieClip = new SWFLoader();
myLoader.load(
  this,
  "main.swf",
  onLoadFunction,
  onCompleteFunction,
  childDefAlpha,
  loadProgressDefAlpha,
  delaySecond,
  isLoadProgressBar
);
  • ローディングバーにグローフィルタを適用しない
1
2
3
4
5
6
7
8
9
10
11
12
13
14
var isLoadProgressBarFilter:Boolean = false;

var myLoader:MovieClip = new SWFLoader();
myLoader.load(
  this,
  "main.swf",
  onLoadFunction,
  onCompleteFunction,
  childDefAlpha,
  loadProgressDefAlpha,
  delaySecond,
  isLoadProgressBar,
  isLoadProgressBarFilter
);
  • ローディングアイコンを表示する
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
var isLoadProgressIcon:Boolean = true;

var myLoader:MovieClip = new SWFLoader();
myLoader.load(
  this,
  "main.swf",
  onLoadFunction,
  onCompleteFunction,
  childDefAlpha,
  loadProgressDefAlpha,
  delaySecond,
  isLoadProgressBar,
  isLoadProgressBarFilter,
  isLoadProgressIcon
);
  • パーセントテキストを表示する
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
var isLoadProgressPercent:Boolean = true;

var myLoader:MovieClip = new SWFLoader();
myLoader.load(
  this,
  "main.swf",
  onLoadFunction,
  onCompleteFunction,
  childDefAlpha,
  loadProgressDefAlpha,
  delaySecond,
  isLoadProgressBar,
  isLoadProgressBarFilter,
  isLoadProgressIcon,
  isLoadProgressPercent
);

ロード状況の取得方法

  • ローディング中であればメッセージを出力する
1
if(SWFLoader.loading) trace("まだ読み込み中です…(TT)");
  • ロードが完了していればメッセージを出力する
1
if(SWFLoader.complete) trace("読み込みが完了しました\(^o^)/");
  • 外部ファイルの総容量(バイト数)を出力する
1
trace(SWFLoader.bytesTotal);
  • 外部ファイルの読み込みが完了した容量(バイト数)を出力する
1
trace(SWFLoader.bytesLoaded);
  • 外部ファイルの読み込みが完了した割合(パーセント)を出力する
1
trace(SWFLoader.percent);

パラメータ解説

$parent

外部ファイルをロードするターゲット

[DisplayObjectContainer][省略不可]

url

ロードする外部ファイルへのパス

[String][省略不可]

onLoadFunction

ロード開始時に実行される関数

[Function][規定値:null][省略可]

onCompleteFunction

ロード完了後に実行される関数

[Function][規定値:null][省略可]

childDefAlpha

外部ファイルのアルファ(初期値)

[Number][規定値:0][省略可]

loadProgressDefAlpha

プログレスバーのアルファ(初期値)

[Number][規定値:0][省略可]

delaySecond

ロード開始するまでの待機時間(秒数)

[Number][規定値:0][省略可]

isLoadProgressBar

プログレスバーの表示

[Boolean][規定値:true][省略可]

isLoadProgressBarFilter

プログレスバーへグローフィルタを適用する

[Boolean][規定値:true][省略可]

isLoadProgressIcon

ローディングアイコンの表示

[Boolean][規定値:false][省略可]

isLoadProgressPercent

パーセントテキストの表示

[Boolean][規定値:false][省略可]

addedLoadClip

別のプログレスバーの指定

[Sprite][規定値:null][省略可]

ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
package net.dolice.net{
  import flash.display.DisplayObjectContainer;
  import flash.display.MovieClip;
  import flash.display.Sprite;
  import flash.display.Loader;
  import flash.display.LoaderInfo;
  import flash.geom.Rectangle;
  import flash.filters.BitmapFilterQuality;
  import flash.events.Event;
  import flash.events.IOErrorEvent;
  import flash.events.ProgressEvent;
  import flash.net.URLRequest;
  import flash.utils.Timer;
  import flash.events.TimerEvent;
  import caurina.transitions.Tweener;
  public class SWFLoader extends MovieClip {
      private var $parent:DisplayObjectContainer;
      private var $child:Loader;
      private var $url:URLRequest;
      protected static var onLoadFunction:Function;
      protected static var onCompleteFunction:Function;
      private var childDefAlpha:Number;
      private var loadProgressDefAlpha:Number;
      private static var isLoadProgressBar:Boolean;
      private static var isLoadProgressBarFilter:Boolean;
      private static var isLoadProgressIcon:Boolean;
      private static var isLoadProgressPercent:Boolean;
      private static var addedLoadProgress;
      public static var currentLoadProgress;
      private static var loadProgress:LoadProgress;
      private static var loadProgressBarColor:uint = 0xFFFFFF;
      private static var loadProgressBaseColor:uint = 0x333333;
      private static var loadProgressX:int = 16;
      private static var loadProgressY:int = 24;
      private static var loadProgressWidth:uint = 135;
      private static var loadProgressHeight:uint = 1;
      private static var loadProgressRectangle:Rectangle;
      private static var loadProgressFilterColor:uint = 0xFFFFFF;
      private static var loadProgressFilterAlpha:Number = 0.8;
      private static var loadProgressFilterBlurX:Number = 2;
      private static var loadProgressFilterBlurY:Number = 2;
      private static var loadProgressFilterStrength:Number = 2;
      private static var loadProgressFilterQuality:Number = BitmapFilterQuality.HIGH;
      private static var loadProgressFilterInner:Boolean = false;
      private static var loadProgressFilterKnockout:Boolean = false;
      private static var loadProgressPercentFont:String = "_serif";
      private static var loadProgressPercentFontSize:uint = 12;
      private static var loadProgressPercentFontColor:uint = 0xFFFFFF;
      private static var loadProgressFadeInParams:Array = [.25,"Strong.easeOut",0];
      private static var loadProgressFadeOutParams:Array = [.5,"easeInOutCubic",0];
      private static var childFadeInParams:Array = [1,"liner",0];
      private static var isDeleteLoadProgress:Boolean = false;
      private static var isLoading:Boolean = false;
      private static var totalBytes:Number;
      private static var loadedBytes:Number;
      private static var per:uint;
      private var loadTimer:Timer;
      private var Tween:Function = Tweener.addTween;
      private var removeTween:Function = Tweener.removeTweens;
      public function load(
          $parent:DisplayObjectContainer,
          url:String,
          onLoadFunction:Function=null,
          onCompleteFunction:Function=null,
          childDefAlpha:Number=0,
          loadProgressDefAlpha:Number=0,
          delaySecond:Number=0,
          isLoadProgressBar:Boolean=true,
          isLoadProgressBarFilter:Boolean=true,
          isLoadProgressIcon:Boolean=false,
          isLoadProgressPercent:Boolean=false,
          addedLoadClip:Sprite=null
      ):void {
          this.$child = new Loader();
          this.$parent = $parent;
          this.$parent.addChildAt($child, this.$parent.numChildren);
          this.$url = new URLRequest(url);
          SWFLoader.onLoadFunction = onLoadFunction;
          SWFLoader.onCompleteFunction = onCompleteFunction;
          this.childDefAlpha = childDefAlpha;
          this.loadProgressDefAlpha = loadProgressDefAlpha;
          delaySecond ? loadTimer = new Timer(delaySecond * 1000,0):loadTimer = null;
          SWFLoader.loadProgressBar = isLoadProgressBar;
          SWFLoader.loadProgressBarFilter = isLoadProgressBarFilter;
          SWFLoader.loadProgressIcon = isLoadProgressIcon;
          SWFLoader.loadProgressPercent = isLoadProgressPercent;
          if (addedLoadClip) {
              SWFLoader.addedLoadProgress = addedLoadClip;
          } else {
              if (SWFLoader.rectangle == null) {
                  SWFLoader.rectangle = new Rectangle(
                      SWFLoader.x,
                      SWFLoader.y,
                      SWFLoader.width,
                      SWFLoader.height
                  );
              }
              SWFLoader.loadProgress = new LoadProgress(
                  SWFLoader.barColor,
                  SWFLoader.baseColor,
                  SWFLoader.rectangle,
                  SWFLoader.filterColor,
                  SWFLoader.filterAlpha,
                  SWFLoader.filterBlurX,
                  SWFLoader.filterBlurY,
                  SWFLoader.filterStrength,
                  SWFLoader.filterQuality,
                  SWFLoader.filterInner,
                  SWFLoader.filterKnockout,
                  SWFLoader.percentFont,
                  SWFLoader.percentFontSize,
                  SWFLoader.percentFontColor,
                  SWFLoader.loadProgressBar,
                  SWFLoader.loadProgressBarFilter,
                  SWFLoader.loadProgressIcon,
                  SWFLoader.loadProgressPercent
              );
          }
          if (SWFLoader.addedLoadProgress) {
              SWFLoader.currentLoadProgress = SWFLoader.addedLoadProgress;
          } else {
              SWFLoader.currentLoadProgress = SWFLoader.loadProgress;
          }
          $parent.addChildAt(
              SWFLoader.currentLoadProgress,
              $parent.numChildren
          );
          with (SWFLoader.currentLoadProgress) {
              alpha = 0;
              visible = false;
          }
          $child.contentLoaderInfo.addEventListener(Event.OPEN, onLoadHandler);
          $child.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, onProgressHandler);
          $child.contentLoaderInfo.addEventListener(Event.COMPLETE, onCompleteHandler);
          $child.contentLoaderInfo.addEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
          $child.visible = false;
          $child.alpha = this.childDefAlpha;
          loadTimer ? setLoadTimer():execLoad();
      }
      private function setLoadTimer():void {
          loadTimer.addEventListener(TimerEvent.TIMER, execLoadTimer);
          loadTimer.start();
      }
      private function execLoadTimer(event:TimerEvent) {
          loadTimer.removeEventListener(TimerEvent.TIMER, execLoadTimer);
          execLoad();
      }
      private function execLoad():void {
          $child.load($url);
      }
      private function onLoadHandler(event:Event):void {
          with (SWFLoader.currentLoadProgress) {
              alpha = loadProgressDefAlpha;
              visible = true;
          }
          if (SWFLoader.currentLoadProgress.alpha < 1) {
              Tween(SWFLoader.currentLoadProgress,{
                  alpha:1,
                  time:SWFLoader.loadProgressFadeInSecond,
                  transition:SWFLoader.loadProgressFadeInEase,
                  delay:SWFLoader.loadProgressFadeInDelay
              });
          }
          if (SWFLoader.onLoadFunction != null) {
              SWFLoader.onLoadFunction();
          }
          SWFLoader.isLoading = true;
      }
      private function onProgressHandler(event:ProgressEvent):void {
          SWFLoader.bytesTotal = event.bytesTotal;
          SWFLoader.bytesLoaded = event.bytesLoaded;
          SWFLoader.percent = Math.floor(SWFLoader.bytesLoaded / SWFLoader.bytesTotal * 100);
          if (SWFLoader.loadProgressBar) {
              SWFLoader.currentLoadProgress.bar.scaleX = SWFLoader.bytesLoaded / SWFLoader.bytesTotal;
          }
          if (SWFLoader.loadProgressPercent) {
              SWFLoader.currentLoadProgress.percent.getChildByName("percentText").text = String(SWFLoader.percent) + "%";
          }
      }
      private function onCompleteHandler(event:Event):void {
          Tween(SWFLoader.currentLoadProgress,{
              alpha:0,
              time:SWFLoader.loadProgressFadeOutSecond,
              transition:SWFLoader.loadProgressFadeOutEase,
              delay:SWFLoader.loadProgressFadeOutDelay,
              onComplete:onFinish
          });
          if (SWFLoader.onCompleteFunction != null) {
              SWFLoader.onCompleteFunction();
          }
          SWFLoader.isLoading = false;
      }
      private function onFinish():void {
          $child.contentLoaderInfo.removeEventListener(Event.OPEN, onLoadHandler);
          $child.contentLoaderInfo.removeEventListener(ProgressEvent.PROGRESS, onProgressHandler);
          $child.contentLoaderInfo.removeEventListener(Event.COMPLETE, onCompleteHandler);
          $child.contentLoaderInfo.removeEventListener(IOErrorEvent.IO_ERROR, onIOErrorHandler);
          $child.visible = true;
          if ($child.alpha < 1) {
              Tween($child, {
                  alpha:1,
                  time:SWFLoader.childFadeInSecond,
                  transition:SWFLoader.childFadeInEase,
                  delay:SWFLoader.childFadeInDelay,
                  onComplete:removeTween,
                  onCompleteParams:[$child]
              });
          }
          if (SWFLoader.clearLoadProgress) {
              deleteLoadProgress();
          }
      }
      private function deleteLoadProgress():void {
          while (SWFLoader.currentLoadProgress.numChildren > 0) {
              SWFLoader.currentLoadProgress.removeChildAt(0);
          }
          removeTween(SWFLoader.currentLoadProgress);
      }
      private function onIOErrorHandler(event:IOErrorEvent):void {
          trace(event);
      }
      public static function get loading():Boolean {
          return (SWFLoader.isLoading);
      }
      public static function get complete():Boolean {
          return !(SWFLoader.isLoading);
      }
      public static function set bytesTotal(totalBytes:Number):void {
          SWFLoader.totalBytes = totalBytes;
      }
      public static function get bytesTotal():Number {
          return (SWFLoader.totalBytes);
      }
      public static function set bytesLoaded(loadedBytes:Number):void {
          SWFLoader.loadedBytes = loadedBytes;
      }
      public static function get bytesLoaded():Number {
          return (SWFLoader.loadedBytes);
      }
      public static function set percent(p:uint):void {
          SWFLoader.per = p;
      }
      public static function get percent():uint {
          return (SWFLoader.per);
      }
      public static function set clearLoadProgress(b:Boolean):void {
          SWFLoader.isDeleteLoadProgress = b;
      }
      public static function get clearLoadProgress():Boolean {
          return (SWFLoader.isDeleteLoadProgress);
      }
      public static function set loadProgressBar(b:Boolean):void {
          SWFLoader.isLoadProgressBar = b;
      }
      public static function get loadProgressBar():Boolean {
          return (SWFLoader.isLoadProgressBar);
      }
      public static function set loadProgressBarFilter(b:Boolean):void {
          SWFLoader.isLoadProgressBarFilter = b;
      }
      public static function get loadProgressBarFilter():Boolean {
          return (SWFLoader.isLoadProgressBarFilter);
      }
      public static function set loadProgressIcon(b:Boolean):void {
          SWFLoader.isLoadProgressIcon = b;
      }
      public static function get loadProgressIcon():Boolean {
          return (SWFLoader.isLoadProgressIcon);
      }
      public static function set loadProgressPercent(b:Boolean):void {
          SWFLoader.isLoadProgressPercent = b;
      }
      public static function get loadProgressPercent():Boolean {
          return (SWFLoader.isLoadProgressPercent);
      }
      public static function set barColor($color:uint):void {
          SWFLoader.loadProgressBarColor = $color;
      }
      public static function get barColor():uint {
          return (SWFLoader.loadProgressBarColor);
      }
      public static function set baseColor($color:uint):void {
          SWFLoader.loadProgressBaseColor = $color;
      }
      public static function get baseColor():uint {
          return (SWFLoader.loadProgressBaseColor);
      }
      public static function set x($x:int):void {
          SWFLoader.loadProgressX = $x;
      }
      public static function get x():int {
          return (SWFLoader.loadProgressX);
      }
      public static function set y($y:int):void {
          SWFLoader.loadProgressY = $y;
      }
      public static function get y():int {
          return (SWFLoader.loadProgressY);
      }
      public static function set width($width:uint):void {
          SWFLoader.loadProgressWidth = $width;
      }
      public static function get width():uint {
          return (SWFLoader.loadProgressWidth);
      }
      public static function set height($height:uint):void {
          SWFLoader.loadProgressHeight = $height;
      }
      public static function get height():uint {
          return (SWFLoader.loadProgressHeight);
      }
      public static function set rectangle($rectangle:Rectangle):void {
          SWFLoader.loadProgressRectangle = $rectangle;
      }
      public static function get rectangle():Rectangle {
          return (SWFLoader.loadProgressRectangle);
      }
      public static function set filterColor($color:uint):void {
          SWFLoader.loadProgressFilterColor = $color;
      }
      public static function get filterColor():uint {
          return (SWFLoader.loadProgressFilterColor);
      }
      public static function set filterAlpha($alpha:Number):void {
          SWFLoader.loadProgressFilterAlpha = $alpha;
      }
      public static function get filterAlpha():Number {
          return (SWFLoader.loadProgressFilterAlpha);
      }
      public static function set filterBlurX($blurX:Number):void {
          SWFLoader.loadProgressFilterBlurX = $blurX;
      }
      public static function get filterBlurX():Number {
          return (SWFLoader.loadProgressFilterBlurX);
      }
      public static function set filterBlurY($blurY:Number):void {
          SWFLoader.loadProgressFilterBlurY = $blurY;
      }
      public static function get filterBlurY():Number {
          return (SWFLoader.loadProgressFilterBlurY);
      }
      public static function set filterStrength($strength:Number):void {
          SWFLoader.loadProgressFilterStrength = $strength;
      }
      public static function get filterStrength():Number {
          return (SWFLoader.loadProgressFilterStrength);
      }
      public static function set filterQuality($quality:Number):void {
          SWFLoader.loadProgressFilterStrength = $quality;
      }
      public static function get filterQuality():Number {
          return (SWFLoader.loadProgressFilterQuality);
      }
      public static function set filterInner($inner:Boolean):void {
          SWFLoader.loadProgressFilterInner = $inner;
      }
      public static function get filterInner():Boolean {
          return (SWFLoader.loadProgressFilterInner);
      }
      public static function set filterKnockout($knockout:Boolean):void {
          SWFLoader.loadProgressFilterKnockout = $knockout;
      }
      public static function get filterKnockout():Boolean {
          return (SWFLoader.loadProgressFilterKnockout);
      }
      public static function set percentFont($font:String):void {
          SWFLoader.loadProgressPercentFont = $font;
      }
      public static function get percentFont():String {
          return (SWFLoader.loadProgressPercentFont);
      }
      public static function set percentFontSize($fontSize:uint):void {
          SWFLoader.loadProgressPercentFontSize = $fontSize;
      }
      public static function get percentFontSize():uint {
          return (SWFLoader.loadProgressPercentFontSize);
      }
      public static function set percentFontColor($fontColor:uint):void {
          SWFLoader.loadProgressPercentFontColor = $fontColor;
      }
      public static function get percentFontColor():uint {
          return (SWFLoader.loadProgressPercentFontColor);
      }
      public static function set loadProgressFadeInSecond(sec:Number):void {
          SWFLoader.loadProgressFadeInParams[0] = sec;
      }
      public static function get loadProgressFadeInSecond():Number {
          return (SWFLoader.loadProgressFadeInParams[0]);
      }
      public static function set loadProgressFadeInEase(ease:String):void {
          SWFLoader.loadProgressFadeInParams[1] = ease;
      }
      public static function get loadProgressFadeInEase():String {
          return (SWFLoader.loadProgressFadeInParams[1]);
      }
      public static function set loadProgressFadeInDelay(delay:Number):void {
          SWFLoader.loadProgressFadeInParams[2] = delay;
      }
      public static function get loadProgressFadeInDelay():Number {
          return (SWFLoader.loadProgressFadeInParams[2]);
      }
      public static function set loadProgressFadeOutSecond(sec:Number):void {
          SWFLoader.loadProgressFadeOutParams[0] = sec;
      }
      public static function get loadProgressFadeOutSecond():Number {
          return (SWFLoader.loadProgressFadeOutParams[0]);
      }
      public static function set loadProgressFadeOutEase(ease:String):void {
          SWFLoader.loadProgressFadeOutParams[1] = ease;
      }
      public static function get loadProgressFadeOutEase():String {
          return (SWFLoader.loadProgressFadeOutParams[1]);
      }
      public static function set loadProgressFadeOutDelay(delay:Number):void {
          SWFLoader.loadProgressFadeOutParams[2] = delay;
      }
      public static function get loadProgressFadeOutDelay():Number {
          return (SWFLoader.loadProgressFadeOutParams[2]);
      }
      public static function set childFadeInSecond(sec:Number):void {
          SWFLoader.childFadeInParams[0] = sec;
      }
      public static function get childFadeInSecond():Number {
          return (SWFLoader.childFadeInParams[0]);
      }
      public static function set childFadeInEase(ease:String):void {
          SWFLoader.childFadeInParams[1] = ease;
      }
      public static function get childFadeInEase():String {
          return (SWFLoader.childFadeInParams[1]);
      }
      public static function set childFadeInDelay(delay:Number):void {
          SWFLoader.childFadeInParams[2] = delay;
      }
      public static function get childFadeInDelay():Number {
          return (SWFLoader.childFadeInParams[2]);
      }
  }
}
import flash.display.Sprite;
import flash.display.MovieClip;
import flash.display.Shape;
import flash.geom.Rectangle;
import flash.text.TextField;
import flash.text.TextFormat;
import flash.filters.BitmapFilterQuality;
import flash.filters.GlowFilter;
internal class LoadProgress extends Sprite {
  public var bar:Sprite = new Sprite();
  public var base:Sprite = new Sprite();
  private var barShape:Shape;
  private var baseShape:Shape;
  public var icon:MovieClip;
  public var percent:Sprite = new Sprite();
  private var percentText:TextField = new TextField();
  private var percentTextFormat:TextFormat = new TextFormat();
  public function LoadProgress(
      barColor:uint,
      baseColor:uint,
      barRectangle:Rectangle,
      filterColor:uint,
      filterAlpha:Number,
      filterBlurX:Number,
      filterBlurY:Number,
      filterStrength:Number,
      filterQuality:Number,
      filterInner:Boolean,
      filterKnockout:Boolean,
      percentFont:String,
      percentFontSize:uint,
      percentFontColor:uint,
      isLoadProgressBar:Boolean,
      isLoadProgressBarFilter:Boolean,
      isLoadProgressIcon:Boolean,
      isLoadProgressPercent:Boolean
   ):void {
      if (isLoadProgressBar) {
          barShape = drawnShape(barColor,barRectangle);
          baseShape = drawnShape(baseColor,barRectangle);
          addLoadProgressBar(base, baseShape, "baseShape", this.numChildren,barRectangle);
          addLoadProgressBar(bar, barShape, "barShape", this.numChildren,barRectangle);
          if (isLoadProgressBarFilter) {
              setLoadProgressBarFilter(bar,
                  glowFilter(
                      filterColor,
                      filterAlpha,
                      filterBlurX,
                      filterBlurY,
                      filterStrength,
                      filterQuality,
                      filterInner,
                      filterKnockout
                  )
              );
          }
          initLoadProgressBarScale(bar, 0);
      }
      if (isLoadProgressIcon) {
          addLoadProgressIcon("icon", this.numChildren);
      }
      if (isLoadProgressPercent) {
          addLoadProgressPercent(percent, percentText, "percentText", this.numChildren);
          setPercentTextFormat(percentFont, percentFontSize, percentFontColor);
          setPercentTextField();
      }
  }
  private function drawnShape($color:uint, $rectangle:Rectangle):Shape {
      var shape:Shape = new Shape();
      shape.graphics.beginFill($color);
      shape.graphics.drawRect(0,0,$rectangle.width,$rectangle.height);
      return Shape(shape);
  }
  private function addLoadProgressBar($parent:Sprite, $child:Shape, $name:String, $depth:int, $rectangle:Rectangle):void {
      this.addChildAt($parent, $depth);
      $parent.x = $rectangle.x;
      $parent.y = $rectangle.y;
      $parent.addChildAt($child, 0);
      $child.name = $name;
  }
  private function setLoadProgressBarFilter($bar:Sprite, $filters:GlowFilter):void {
      $bar.filters = [$filters];
  }
  private function initLoadProgressBarScale($bar:Sprite, $scaleX:Number):void {
      $bar.scaleX = $scaleX;
  }
  private function addLoadProgressIcon($name:String, $depth:int):void {
      icon = new LoadProgressIcon();//この行でライブラリのリンケージクラス LoadProgressIcon」を使用しています
      this.addChildAt(icon, $depth);
      icon.name = $name;
  }
  private function addLoadProgressPercent($parent:Sprite, $child:TextField, $name:String, $depth:int):void {
      this.addChildAt($parent, $depth);
      $parent.addChildAt($child, 0);
      $child.name = $name;
  }
  private function setPercentTextFormat(font:String, size:uint, color:uint):void {
      percentTextFormat.font = font;
      percentTextFormat.size = size;
      percentTextFormat.color = color;
  }
  private function setPercentTextField():void {
      percentText.autoSize = "left";
      percentText.multiline = false;
      percentText.wordWrap = false;
      percentText.selectable = false;
      percentText.mouseWheelEnabled = false;
      percentText.defaultTextFormat = percentTextFormat;
      percentText.text = String(0);
  }
  private function glowFilter(
      color:uint=0xFFFFFF,
      alpha:Number=.8,
      blurX:Number=2,
      blurY:Number=2,
      strength:Number=2,
      quality:Number=BitmapFilterQuality.HIGH,
      inner:Boolean=false,
      knockout:Boolean=false
  ):GlowFilter {
      return new GlowFilter(
          color,
          alpha,
          blurX,
          blurY,
          strength,
          quality,
          inner,
          knockout
      );
  }
}
   このエントリーをはてなブックマークに追加

About

Masaki Hirokawa (@dolice_apps)

デザインエンジニア 廣川政樹の開発ブログ。Objective-Cや Javaなど iPhone/Androidアプリ開発に関する技術情報を掲載しています。

iPhone apps

  • リラックス・ヒーリング(無料)
  • 望みが叶う!引き寄せの法則アプリ(無料)
  • ミステリー - 怖い話や不思議な体験、都市伝説まとめ
  • 浮世絵壁紙 - 美しい日本画ギャラリー(無料)
  • アート壁紙HD(無料)
  • 綺麗な壁紙HD iPhone 7/7 Plus/SE & iPod対応(無料)
  • クールな壁紙HD iPhone 7/7 Plus/SE & iPod対応(無料)

Android apps

  • 浮世絵壁紙 - 美しい日本画ギャラリー
  • 綺麗な高画質壁紙

Objective-C Classes

Tag Cloud

ActionScript(9) ActionScript3(7) Ad(4) Adfurikun(2) AdMob(9) Android(10) Animation(17) AppDelegate(3) ARC(1) ArrayList(1) AVAudioPlayer(4) AVAudioSession(1) AVFoundation(3) Banner(2) Bitmap(1) Camera(4) CGAffineTransform(4) CGBlendMode(2) CGContextRef(1) CGImageRef(1) Classes(44) CLLocationManager(1) ConnectivityManager(1) ContentResolver(1) CoreLocation(2) Delegate(3) Device(7) Display(1) DisplayMetrics(1) Download(101) Facebook(6) Foundation(72) Framework(2) Google Analytics(1) Handler(1) iAd(6) ImageView(1) In-AppPurchase(1) iOS(12) iOS 7(15) iOS 7.1(3) iOS 8(1) iPad(7) iPhone(21) iPhone 6(4) Java(7) JavaScript(2) LINE(4) Localize(1) Magazine(1) MediaStore(1) MFComposeViewController(1) Nend(1) NetworkInfo(1) NSArray(23) NSCalendar(3) NSData(2) NSDate(7) NSDateComponents(2) NSDateFormatter(2) NSDictionary(12) NSEnumerator(1) NSIndexSet(1) NSInteger(6) NSMutableArray(17) NSMutableDictionary(5) NSMutableOrderedSet(7) NSMutableString(4) NSMutableURLRequest(1) NSNotificationCenter(1) NSNumber(1) NSObject(1) NSOrderedSet(7) NSRange(2) NSSelectorFromString(1) NSSet(6) NSString(19) NSTimer(4) NSTimeZone(1) NSURL(7) NSURLConnection(1) NSURLRequest(2) NSUserDefaults(7) NSXMLParser(2) Objective-C(222) PHP(1) Products(14) QuartzCore(3) RSS(2) Runnable(1) Sample(51) Screensaver(9) SDK(2) ShareCompat(1) Social(10) StoreKit(1) Twitter(6) UIAccelerometer(3) UIActionSheet(1) UIActivityIndicator(1) UIActivityIndicatorView(3) UIActivityViewController(1) UIAlertView(5) UIApplication(7) UIButton(4) UIColor(3) UIDatePicker(5) UIDevice(6) UIDeviceOrientation(1) UIEvent(6) UIImage(15) UIImagePickerController(4) UIImageView(12) UIKit(58) UILabel(7) UINavigationBar(4) UINavigationItem(1) UIPasteboard(4) UIScreen(1) UIScrollBar(1) UIScrollView(1) UISlider(3) UIStoryboardSegue(3) UISwitch(1) UITabBar(3) UITableView(4) UITextField(2) UIView(11) UIViewAnimationTransition(1) UIViewController(4) UIWebView(5) WindowManager(1) Xcode(48) Xcode 5(8) Xcode 5.1(2)