Loading.as 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /**
  2. * ...
  3. * @author Default
  4. * @version 0.1
  5. */
  6. package {
  7. import flash.display.Sprite;
  8. import flash.text.TextField;
  9. import flash.text.TextFormat;
  10. import flash.events.Event;
  11. import flash.filters.DropShadowFilter;
  12. public class Loading extends Sprite {
  13. private var tf:TextField;
  14. public function Loading( text:String ) {
  15. this.tf = new TextField();
  16. this.tf.text = text;
  17. var fmt:TextFormat = new TextFormat();
  18. fmt.color = 0x000000;
  19. fmt.font = "Verdana";
  20. fmt.size = 12;
  21. fmt.align = "center";
  22. this.tf.setTextFormat(fmt);
  23. this.tf.autoSize = "left";
  24. this.tf.x = 5;
  25. this.tf.y = 5;
  26. //
  27. // HACK! For some reason the Stage.height is not
  28. // correct the very first time this object is created
  29. // so we wait untill the first frame before placing
  30. // the movie clip at the center of the Stage.
  31. //
  32. this.addEventListener( Event.ENTER_FRAME, this.onEnter );
  33. this.addChild( this.tf );
  34. this.graphics.lineStyle( 2, 0x808080, 1 );
  35. this.graphics.beginFill( 0xf0f0f0 );
  36. this.graphics.drawRoundRect(0, 0, this.tf.width + 10, this.tf.height + 10, 5, 5);
  37. var spin:Sprite = new Sprite();
  38. spin.x = this.tf.width + 40;
  39. spin.y = (this.tf.height + 10) / 2;
  40. var radius:Number = 15;
  41. var dots:Number = 6;
  42. var colours:Array = [0xF0F0F0,0xD0D0D0,0xB0B0B0,0x909090,0x707070,0x505050,0x303030];
  43. for( var i:Number=0; i<dots; i++ )
  44. {
  45. var deg:Number = (360/dots)*i;
  46. var radians:Number = deg * (Math.PI/180);
  47. var x:Number = radius * Math.cos(radians);
  48. var y:Number = radius * Math.sin(radians);
  49. spin.graphics.lineStyle(0, 0, 0);
  50. spin.graphics.beginFill( colours[i], 1 );
  51. spin.graphics.drawCircle( x, y, 4 );
  52. }
  53. this.addChild( spin );
  54. var dropShadow:DropShadowFilter = new DropShadowFilter();
  55. dropShadow.blurX = 4;
  56. dropShadow.blurY = 4;
  57. dropShadow.distance = 4;
  58. dropShadow.angle = 45;
  59. dropShadow.quality = 2;
  60. dropShadow.alpha = 0.5;
  61. // apply shadow filter
  62. this.filters = [dropShadow];
  63. /*
  64. spin.onEnterFrame = function ()
  65. {
  66. this._rotation += 5;
  67. }
  68. */
  69. }
  70. private function onEnter(event:Event):void {
  71. if( this.stage ) {
  72. this.x = (this.stage.stageWidth/2)-((this.tf.width+10)/2);
  73. this.y = (this.stage.stageHeight/2)-((this.tf.height+10)/2);
  74. // this.removeEventListener( Event.ENTER_FRAME, this.onEnter );
  75. // tr.ace('ppp');
  76. }
  77. this.getChildAt(1).rotation += 5;
  78. }
  79. }
  80. }