Flash预加载程序as3类似苹果风格的代码。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Flash预加载程序as3类似苹果风格的代码。相关的知识,希望对你有一定的参考价值。

AS3 Apple Style Preloader
  1. package net.stevensacks.preloaders
  2. {
  3. import flash.events.TimerEvent;
  4. import flash.events.Event;
  5. import flash.display.Sprite;
  6. import flash.display.Shape;
  7. import flash.utils.Timer;
  8.  
  9. public class CircleSlicePreloader extends Sprite
  10. {
  11. private var timer:Timer;
  12. private var slices:int;
  13. private var radius:int;
  14.  
  15. public function CircleSlicePreloader(slices:int = 12, radius:int = 6)
  16. {
  17. super();
  18. this.slices = slices;
  19. this.radius = radius;
  20. draw();
  21. addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
  22. }
  23. private function onAddedToStage(event:Event):void
  24. {
  25. removeEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
  26. addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
  27. timer = new Timer(65);
  28. timer.addEventListener(TimerEvent.TIMER, onTimer, false, 0, true);
  29. timer.start();
  30. }
  31. private function onRemovedFromStage(event:Event):void
  32. {
  33. removeEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
  34. addEventListener(Event.ADDED_TO_STAGE, onAddedToStage);
  35. timer.reset();
  36. timer.removeEventListener(TimerEvent.TIMER, onTimer);
  37. timer = null;
  38. }
  39. private function onTimer(event:TimerEvent):void
  40. {
  41. rotation = (rotation + (360 / slices)) % 360;
  42. }
  43. private function draw():void
  44. {
  45. var i:int = slices;
  46. var degrees:int = 360 / slices;
  47. while (i--)
  48. {
  49. var slice:Shape = getSlice();
  50. slice.alpha = Math.max(0.2, 1 - (0.1 * i));
  51. var radianAngle:Number = (degrees * i) * Math.PI / 180;
  52. slice.rotation = -degrees * i;
  53. slice.x = Math.sin(radianAngle) * radius;
  54. slice.y = Math.cos(radianAngle) * radius;
  55. addChild(slice);
  56. }
  57. }
  58. private function getSlice():Shape
  59. {
  60. var slice:Shape = new Shape();
  61. slice.graphics.beginFill(0x666666);
  62. slice.graphics.drawRoundRect(-1, 0, 2, 6, 12, 12);
  63. slice.graphics.endFill();
  64. return slice;
  65. }
  66. }
  67. }

以上是关于Flash预加载程序as3类似苹果风格的代码。的主要内容,如果未能解决你的问题,请参考以下文章

在 AS3 Flash Builder 中为 SWF 创建预加载器

AS3:预加载程序代码

如何在 AS3 中创建预加载器

ActionScript 3 AS3:预加载器代码

flash as3中event/evt/e三者的区别是啥?

AS2 到 AS3 转换错误