Advertisement
Guest User

Untitled

a guest
Oct 5th, 2015
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. package application.comps {
  2. import com.greensock.easing.Expo;
  3. import com.greensock.TweenLite;
  4. import flash.display.DisplayObjectContainer;
  5. import flash.display.Sprite;
  6. import flash.events.EventDispatcher;
  7. import flash.geom.Point;
  8. import flash.utils.getDefinitionByName;
  9.  
  10. public class SparkEffect extends EventDispatcher {
  11. private static var cont:Sprite;
  12. private static var sparkMc:Sprite;
  13. private static var sparksAr:Array;
  14.  
  15. public static function animate(mov:DisplayObjectContainer, sparkleClass:Class, point:Point, sparksNum:int = 20, time:Number = 1, breadth:Number = 60):void {
  16.  
  17. cont = new Sprite();
  18. mov.addChild(cont);
  19. cont.x = point.x;
  20. cont.y = point.y;
  21.  
  22. sparksAr = []
  23.  
  24. for (var i:int = 0; i < sparksNum; i++) {
  25. sparkMc = new sparkleClass();
  26. cont.addChild(sparkMc);
  27.  
  28. sparksAr.push(sparkMc);
  29.  
  30. var rad:Number = Math.random() * 360 * (Math.PI / 180);
  31. TweenLite.to(sparkMc, time, {x: Math.random() * breadth * Math.cos(rad), y: Math.random() * breadth * Math.sin(rad), rotation: Math.random() * 360 * 3, ease: Expo.easeOut, alpha: 0});
  32. }
  33.  
  34. TweenLite.delayedCall(time, clear);
  35. }
  36.  
  37. public static function clear():void {
  38.  
  39. for each (sparkMc in sparksAr) {
  40. TweenLite.killTweensOf(sparkMc);
  41. }
  42.  
  43. if(cont)cont.removeChildren();
  44. if(cont && cont.parent)cont.parent.removeChild(cont);
  45.  
  46. cont = null;
  47. sparkMc = null;
  48. sparksAr = null;
  49. }
  50. }
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement