notice: Flash editor updated! Join the development! Thanks to MiniBuilder


embed

FORKED
  1. // forked from nondelion's Sand Button
  2. package {
  3.     import flash.display.Sprite;
  4.     import flash.utils.setTimeout;
  5.     [SWF(width=465, height=465, backgroundColor=0x00AEEF, frameRate=60)]
  6.     
  7.     public class Main extends Sprite
  8.     {
  9.         private static const TEXTCOLOR:uint = 0xffffff;
  10.         private static const BGCOLOR:uint = 0x00AEEF;
  11.         private static const LABEL_ARRAY:Array = ["","ABOUT","WORKS","CONTACT"];
  12.         
  13.         public function Main()
  14.         {
  15.             init();
  16.         }
  17.         
  18.         private function init():void
  19.         {
  20.             for(var i:int=0; i<4; i++) {
  21.                 var btn:SandButton = new SandButton(LABEL_ARRAY[i],48,TEXTCOLOR,BGCOLOR,false);
  22.                 btn.y = 40*i + 160;
  23.                 btn.x = 120;
  24.                 addChild(btn);
  25.                 setTimeout(btn.appearMotion, 40*(i+1));
  26.             }
  27.         }
  28.     }
  29. }
  30.         import flash.display.Sprite;
  31.     import flash.display.BitmapData;
  32.     import flash.display.Bitmap;
  33.     import flash.events.Event;
  34.     import flash.events.MouseEvent;
  35.     import flash.text.TextField;
  36.     import flash.text.TextFieldAutoSize;
  37.     import flash.text.TextFormat;
  38.     import flash.geom.Rectangle;
  39.     import flash.geom.Point;
  40.     import flash.filters.BlurFilter;
  41.     
  42.     class SandButton extends Sprite
  43.     {
  44.         private static const APPEAR_RANGE:Number = 100;
  45.         private static const TAIL_LENGTH:Number = 30;
  46.         private static const DISTANCE:Number = 500;
  47.         private var bd:BitmapData;
  48.         private var canvas:BitmapData;
  49.         private var particles:Particle;
  50.         private var pnum:uint = 0;
  51.         private var _setup:Boolean;
  52.         
  53.         public function SandButton(buttonLabel:String, size:Number, textColor:uint, bgColor:uint, setup:Boolean)
  54.         {
  55.             _setup = setup;
  56.             
  57.             var tf:TextField = new TextField();
  58.             tf.defaultTextFormat = new TextFormat('Helvetica', size, textColor, true);
  59.             tf.autoSize = TextFieldAutoSize.LEFT;
  60.             tf.text = buttonLabel;
  61.             
  62.             bd = new BitmapData(tf.width+TAIL_LENGTH, tf.height, true, bgColor+(0xff<<24));
  63.             bd.lock();
  64.             bd.fillRect(new Rectangle(tf.width,0,TAIL_LENGTH,tf.height),0x0);
  65.             bd.draw(tf);
  66.             
  67.             var prev:Particle = particles = new Particle();
  68.             var p:Particle;
  69.             
  70.             for (var i:int=0; i < tf.width; i++) {
  71.                 for (var j:int=0; j < tf.height; j++) {
  72.                     var color:uint = bd.getPixel(i, j);
  73.                     if ( color != bgColor ) {
  74.                         p = new Particle();
  75.                         p.x = i;
  76.                         p.y = j;
  77.                         p.sx = (Math.random()+1)*(i+1)*200 + DISTANCE;
  78.                         p.sy = p.y;
  79.                         p.cx = p.sx;
  80.                         p.cy = p.sy;
  81.                         p.vx = 2 + Math.random()*i/200;
  82.                         p.vy = 2;
  83.                         p.color = color;
  84.                         prev.next = p;
  85.                         prev = p;
  86.                         pnum++;
  87.                     } else {
  88.                         bd.setPixel32(i, j, 0x0);
  89.                     }
  90.                 }
  91.             }
  92.             bd.unlock();
  93.             
  94.             if( _setup ) {
  95.                 addChild( new Bitmap( bd ) );
  96.                 initEvent();
  97.             }
  98.         }
  99.         
  100.         private function initEvent():void
  101.         {
  102.             var over:Sprite = new Sprite();
  103.             over.graphics.beginFill(0x0, 0);
  104.             over.graphics.drawRect(0,0,bd.width,bd.height);
  105.             over.graphics.endFill();
  106.             addChild( over );
  107.             
  108.             over.addEventListener( MouseEvent.MOUSE_OVER, clickHandler );
  109.         }
  110.         
  111.         public function appearMotion():void
  112.         {
  113.             if( !_setup ) {
  114.                 bd.fillRect(bd.rect,0x0);
  115.                 addChild( new Bitmap( bd ) );
  116.                 initEvent();
  117.             }
  118.             motion();
  119.         }
  120.         
  121.         private function clickHandler(e:Event):void
  122.         {
  123.             motion();
  124.         }
  125.         
  126.         private function motion():void
  127.         {
  128.             var p:Particle = particles;
  129.             while((p = p.next) != null) {
  130.                 p.cx = p.sx;
  131.                 p.cy = p.sy;
  132.             }
  133.             if( !hasEventListener( Event.ENTER_FRAME ) ) {
  134.                 addEventListener( Event.ENTER_FRAME, update );
  135.             }
  136.         }
  137.         
  138.         private function update(e:Event):void
  139.         {
  140.             var num:int = 0;
  141.             var p:Particle = particles;
  142.             bd.lock();
  143.             bd.fillRect(bd.rect, 0x0);
  144.             
  145.             while((p = p.next) != null) {
  146.              var r:Number = Math.sqrt((p.x-p.cx)*(p.x-p.cx) + (p.y-p.cy)*(p.y-p.cy));
  147.                 p.cx += (p.x - p.cx )/p.vx;
  148.                 p.cy += (p.y - p.cy )/p.vy;
  149.                 if ( Math.abs( p.cx - p.x ) <= 1 && Math.abs( p.cy - p.y) <= 1) {
  150.                     p.cx = p.x;
  151.                     p.cy = p.y;
  152.                     num++;
  153.                 }
  154.                 var a:uint = r < APPEAR_RANGE ? (1-r/APPEAR_RANGE)*255 : 0;
  155.                 var c:uint = p.color + (a << 24);
  156.                 bd.setPixel32(p.cx, p.cy, c);
  157.             }
  158.             bd.unlock();
  159.             if(pnum == num) {
  160.                 e.target.removeEventListener(Event.ENTER_FRAME,arguments.callee);
  161.             }
  162.         }    
  163.     }
  164. class Particle 
  165. {
  166.     public var color:int;
  167.     public var x:Number;
  168.     public var y:Number;
  169.     public var cx:Number;
  170.     public var cy:Number;
  171.     public var sx:Number;
  172.     public var sy:Number;
  173.     public var vx:Number;
  174.     public var vy:Number;
  175.     public var next:Particle;
  176.     
  177.     public function Particle()
  178.     {
  179.         
  180.     }
  181. }
noswf
  1. // forked from nondelion's Sand Button
  2. package {
  3.     import flash.display.Sprite;
  4.     import flash.utils.setTimeout;
  5.     [SWF(width=465, height=465, backgroundColor=0x00AEEF, frameRate=60)]
  6.     
  7.     public class Main extends Sprite
  8.     {
  9.         private static const TEXTCOLOR:uint = 0xffffff;
  10.         private static const BGCOLOR:uint = 0x00AEEF;
  11.         private static const LABEL_ARRAY:Array = ["HOME","ABOUT","WORKS","CONTACT"];
  12.         
  13.         public function Main()
  14.         {
  15.             init();
  16.         }
  17.         
  18.         private function init():void
  19.         {
  20.             for(var i:int=0; i<4; i++) {
  21.                 var btn:SandButton = new SandButton(LABEL_ARRAY[i],48,TEXTCOLOR,BGCOLOR,false);
  22.                 btn.y = 40*i + 160;
  23.                 btn.x = 120;
  24.                 addChild(btn);
  25.                 setTimeout(btn.appearMotion, 40*(i+1));
  26.             }
  27.         }
  28.     }
  29. }
  30.         import flash.display.Sprite;
  31.     import flash.display.BitmapData;
  32.     import flash.display.Bitmap;
  33.     import flash.events.Event;
  34.     import flash.events.MouseEvent;
  35.     import flash.text.TextField;
  36.     import flash.text.TextFieldAutoSize;
  37.     import flash.text.TextFormat;
  38.     import flash.geom.Rectangle;
  39.     import flash.geom.Point;
  40.     import flash.filters.BlurFilter;
  41.     
  42.     class SandButton extends Sprite
  43.     {
  44.         private static const APPEAR_RANGE:Number = 100;
  45.         private static const TAIL_LENGTH:Number = 30;
  46.         private static const DISTANCE:Number = 500;
  47.         private var bd:BitmapData;
  48.         private var canvas:BitmapData;
  49.         private var particles:Particle;
  50.         private var pnum:uint = 0;
  51.         private var _setup:Boolean;
  52.         
  53.         public function SandButton(buttonLabel:String, size:Number, textColor:uint, bgColor:uint, setup:Boolean)
  54.         {
  55.             _setup = setup;
  56.             
  57.             var tf:TextField = new TextField();
  58.             tf.defaultTextFormat = new TextFormat('Helvetica', size, textColor, true);
  59.             tf.autoSize = TextFieldAutoSize.LEFT;
  60.             tf.text = buttonLabel;
  61.             
  62.             bd = new BitmapData(tf.width+TAIL_LENGTH, tf.height, true, bgColor+(0xff<<24));
  63.             bd.lock();
  64.             bd.fillRect(new Rectangle(tf.width,0,TAIL_LENGTH,tf.height),0x0);
  65.             bd.draw(tf);
  66.             
  67.             var prev:Particle = particles = new Particle();
  68.             var p:Particle;
  69.             
  70.             for (var i:int=0; i < tf.width; i++) {
  71.                 for (var j:int=0; j < tf.height; j++) {
  72.                     var color:uint = bd.getPixel(i, j);
  73.                     if ( color != bgColor ) {
  74.                         p = new Particle();
  75.                         p.x = i;
  76.                         p.y = j;
  77.                         p.sx = (Math.random()+1)*(i+1)*200 + DISTANCE;
  78.                         p.sy = p.y;
  79.                         p.cx = p.sx;
  80.                         p.cy = p.sy;
  81.                         p.vx = 2 + Math.random()*i/200;
  82.                         p.vy = 2;
  83.                         p.color = color;
  84.                         prev.next = p;
  85.                         prev = p;
  86.                         pnum++;
  87.                     } else {
  88.                         bd.setPixel32(i, j, 0x0);
  89.                     }
  90.                 }
  91.             }
  92.             bd.unlock();
  93.             
  94.             if( _setup ) {
  95.                 addChild( new Bitmap( bd ) );
  96.                 initEvent();
  97.             }
  98.         }
  99.         
  100.         private function initEvent():void
  101.         {
  102.             var over:Sprite = new Sprite();
  103.             over.graphics.beginFill(0x0, 0);
  104.             over.graphics.drawRect(0,0,bd.width,bd.height);
  105.             over.graphics.endFill();
  106.             addChild( over );
  107.             
  108.             over.addEventListener( MouseEvent.MOUSE_OVER, clickHandler );
  109.         }
  110.         
  111.         public function appearMotion():void
  112.         {
  113.             if( !_setup ) {
  114.                 bd.fillRect(bd.rect,0x0);
  115.                 addChild( new Bitmap( bd ) );
  116.                 initEvent();
  117.             }
  118.             motion();
  119.         }
  120.         
  121.         private function clickHandler(e:Event):void
  122.         {
  123.             motion();
  124.         }
  125.         
  126.         private function motion():void
  127.         {
  128.             var p:Particle = particles;
  129.             while((p = p.next) != null) {
  130.                 p.cx = p.sx;
  131.                 p.cy = p.sy;
  132.             }
  133.             if( !hasEventListener( Event.ENTER_FRAME ) ) {
  134.                 addEventListener( Event.ENTER_FRAME, update );
  135.             }
  136.         }
  137.         
  138.         private function update(e:Event):void
  139.         {
  140.             var num:int = 0;
  141.             var p:Particle = particles;
  142.             bd.lock();
  143.             bd.fillRect(bd.rect, 0x0);
  144.             
  145.             while((p = p.next) != null) {
  146.              var r:Number = Math.sqrt((p.x-p.cx)*(p.x-p.cx) + (p.y-p.cy)*(p.y-p.cy));
  147.                 p.cx += (p.x - p.cx )/p.vx;
  148.                 p.cy += (p.y - p.cy )/p.vy;
  149.                 if ( Math.abs( p.cx - p.x ) <= 1 && Math.abs( p.cy - p.y) <= 1) {
  150.                     p.cx = p.x;
  151.                     p.cy = p.y;
  152.                     num++;
  153.                 }
  154.                 var a:uint = r < APPEAR_RANGE ? (1-r/APPEAR_RANGE)*255 : 0;
  155.                 var c:uint = p.color + (a << 24);
  156.                 bd.setPixel32(p.cx, p.cy, c);
  157.             }
  158.             bd.unlock();
  159.             if(pnum == num) {
  160.                 e.target.removeEventListener(Event.ENTER_FRAME,arguments.callee);
  161.             }
  162.         }    
  163.     }
  164. class Particle 
  165. {
  166.     public var color:int;
  167.     public var x:Number;
  168.     public var y:Number;
  169.     public var cx:Number;
  170.     public var cy:Number;
  171.     public var sx:Number;
  172.     public var sy:Number;
  173.     public var vx:Number;
  174.     public var vy:Number;
  175.     public var next:Particle;
  176.     
  177.     public function Particle()
  178.     {
  179.         
  180.     }
  181. }
noswf
  1. // forked from nondelion's Sand Button
  2. package {
  3.     import flash.display.Sprite;
  4.     import flash.utils.setTimeout;
  5.     [SWF(width=465, height=465, backgroundColor=0x00AEEF, frameRate=60)]
  6.     
  7.     public class Main extends Sprite
  8.     {
  9.         private static const TEXTCOLOR:uint = 0xff0111;
  10.         private static const BGCOLOR:uint = 0x00AfEF;
  11.         private static const LABEL_ARRAY:Array = ["שוריקאן","מתכות כבדות","עזרה וביצרון","CONTACT"];
  12.         
  13.         public function Main()
  14.         {
  15.             init();
  16.         }
  17.         
  18.         private function init():void
  19.         {
  20.             for(var i:int=0; i<4; i++) {
  21.                 var btn:SandButton = new SandButton(LABEL_ARRAY[i],48,TEXTCOLOR,BGCOLOR,false);
  22.                 btn.y = 40*i + 160;
  23.                 btn.x = 120;
  24.                 addChild(btn);
  25.                 setTimeout(btn.appearMotion, 40*(i+1));
  26.             }
  27.         }
  28.     }
  29. }
  30.         import flash.display.Sprite;
  31.     import flash.display.BitmapData;
  32.     import flash.display.Bitmap;
  33.     import flash.events.Event;
  34.     import flash.events.MouseEvent;
  35.     import flash.text.TextField;
  36.     import flash.text.TextFieldAutoSize;
  37.     import flash.text.TextFormat;
  38.     import flash.geom.Rectangle;
  39.     import flash.geom.Point;
  40.     import flash.filters.BlurFilter;
  41.     
  42.     class SandButton extends Sprite
  43.     {
  44.         private static const APPEAR_RANGE:Number = 100;
  45.         private static const TAIL_LENGTH:Number = 30;
  46.         private static const DISTANCE:Number = 500;
  47.         private var bd:BitmapData;
  48.         private var canvas:BitmapData;
  49.         private var particles:Particle;
  50.         private var pnum:uint = 0;
  51.         private var _setup:Boolean;
  52.         
  53.         public function SandButton(buttonLabel:String, size:Number, textColor:uint, bgColor:uint, setup:Boolean)
  54.         {
  55.             _setup = setup;
  56.             
  57.             var tf:TextField = new TextField();
  58.             tf.defaultTextFormat = new TextFormat('Helvetica', size, textColor, true);
  59.             tf.autoSize = TextFieldAutoSize.LEFT;
  60.             tf.text = buttonLabel;
  61.             
  62.             bd = new BitmapData(tf.width+TAIL_LENGTH, tf.height, true, bgColor+(0xff<<24));
  63.             bd.lock();
  64.             bd.fillRect(new Rectangle(tf.width,0,TAIL_LENGTH,tf.height),0x0);
  65.             bd.draw(tf);
  66.             
  67.             var prev:Particle = particles = new Particle();
  68.             var p:Particle;
  69.             
  70.             for (var i:int=0; i < tf.width; i++) {
  71.                 for (var j:int=0; j < tf.height; j++) {
  72.                     var color:uint = bd.getPixel(i, j);
  73.                     if ( color != bgColor ) {
  74.                         p = new Particle();
  75.                         p.x = i;
  76.                         p.y = j;
  77.                         p.sx = (Math.random()+10)*(i+1)*200 + DISTANCE;
  78.                         p.sy = p.y;
  79.                         p.cx = p.sx;
  80.                         p.cy = p.sy;
  81.                         p.vx = 2 + Math.random()*i/200;
  82.                         p.vy = 2;
  83.                         p.color = color;
  84.                         prev.next = p;
  85.                         prev = p;
  86.                         pnum++;
  87.                     } else {
  88.                         bd.setPixel32(i, j, 0x0);
  89.                     }
  90.                 }
  91.             }
  92.             bd.unlock();
  93.             
  94.             if( _setup ) {
  95.                 addChild( new Bitmap( bd ) );
  96.                 initEvent();
  97.             }
  98.         }
  99.         
  100.         private function initEvent():void
  101.         {
  102.             var over:Sprite = new Sprite();
  103.             over.graphics.beginFill(0x0, 0);
  104.             over.graphics.drawRect(0,0,bd.width,bd.height);
  105.             over.graphics.endFill();
  106.             addChild( over );
  107.             
  108.             over.addEventListener( MouseEvent.MOUSE_OVER, clickHandler );
  109.         }
  110.         
  111.         public function appearMotion():void
  112.         {
  113.             if( !_setup ) {
  114.                 bd.fillRect(bd.rect,0x0);
  115.                 addChild( new Bitmap( bd ) );
  116.                 initEvent();
  117.             }
  118.             motion();
  119.         }
  120.         
  121.         private function clickHandler(e:Event):void
  122.         {
  123.             motion();
  124.         }
  125.         
  126.         private function motion():void
  127.         {
  128.             var p:Particle = particles;
  129.             while((p = p.next) != null) {
  130.                 p.cx = p.sx;
  131.                 p.cy = p.sy;
  132.             }
  133.             if( !hasEventListener( Event.ENTER_FRAME ) ) {
  134.                 addEventListener( Event.ENTER_FRAME, update );
  135.             }
  136.         }
  137.         
  138.         private function update(e:Event):void
  139.         {
  140.             var num:int = 0;
  141.             var p:Particle = particles;
  142.             bd.lock();
  143.             bd.fillRect(bd.rect, 0x0);
  144.             
  145.             while((p = p.next) != null) {
  146.              var r:Number = Math.sqrt((p.x-p.cx)*(p.x-p.cx) + (p.y-p.cy)*(p.y-p.cy));
  147.                 p.cx += (p.x - p.cx )/p.vx;
  148.                 p.cy += (p.y - p.cy )/p.vy;
  149.                 if ( Math.abs( p.cx - p.x ) <= 1 && Math.abs( p.cy - p.y) <= 1) {
  150.                     p.cx = p.x;
  151.                     p.cy = p.y;
  152.                     num++;
  153.                 }
  154.                 var a:uint = r < APPEAR_RANGE ? (1-r/APPEAR_RANGE)*255 : 0;
  155.                 var c:uint = p.color + (a << 24);
  156.                 bd.setPixel32(p.cx, p.cy, c);
  157.             }
  158.             bd.unlock();
  159.             if(pnum == num) {
  160.                 e.target.removeEventListener(Event.ENTER_FRAME,arguments.callee);
  161.             }
  162.         }    
  163.     }
  164. class Particle 
  165. {
  166.     public var color:int;
  167.     public var x:Number;
  168.     public var y:Number;
  169.     public var cx:Number;
  170.     public var cy:Number;
  171.     public var sx:Number;
  172.     public var sy:Number;
  173.     public var vx:Number;
  174.     public var vy:Number;
  175.     public var next:Particle;
  176.     
  177.     public function Particle()
  178.     {
  179.         
  180.     }
  181. }
noswf
  1. // forked from nondelion's Sand Button
  2. package {
  3.     import flash.display.Sprite;
  4.     import flash.utils.setTimeout;
  5.     [SWF(width=465, height=465, backgroundColor=0x00AEEF, frameRate=60)]
  6.     
  7.     public class Main extends Sprite
  8.     {
  9.         private static const TEXTCOLOR:uint = 0xffffff;
  10.         private static const BGCOLOR:uint = 0x00AEEF;
  11.         private static const LABEL_ARRAY:Array = ["HOME","ABOUT","WORKS","CONTACT"];
  12.         
  13.         public function Main()
  14.         {
  15.             init();
  16.         }
  17.         
  18.         private function init():void
  19.         {
  20.             for(var i:int=0; i<4; i++) {
  21.                 var btn:SandButton = new SandButton(LABEL_ARRAY[i],48,TEXTCOLOR,BGCOLOR,false);
  22.                 btn.y = 40*i + 160;
  23.                 btn.x = 120;
  24.                 addChild(btn);
  25.                 setTimeout(btn.appearMotion, 40*(i+1));
  26.             }
  27.         }
  28.     }
  29. }
  30.         import flash.display.Sprite;
  31.     import flash.display.BitmapData;
  32.     import flash.display.Bitmap;
  33.     import flash.events.Event;
  34.     import flash.events.MouseEvent;
  35.     import flash.text.TextField;
  36.     import flash.text.TextFieldAutoSize;
  37.     import flash.text.TextFormat;
  38.     import flash.geom.Rectangle;
  39.     import flash.geom.Point;
  40.     import flash.filters.BlurFilter;
  41.     
  42.     class SandButton extends Sprite
  43.     {
  44.         private static const APPEAR_RANGE:Number = 100;
  45.         private static const TAIL_LENGTH:Number = 30;
  46.         private static const DISTANCE:Number = 500;
  47.         private var bd:BitmapData;
  48.         private var canvas:BitmapData;
  49.         private var particles:Particle;
  50.         private var pnum:uint = 0;
  51.         private var _setup:Boolean;
  52.         
  53.         public function SandButton(buttonLabel:String, size:Number, textColor:uint, bgColor:uint, setup:Boolean)
  54.         {
  55.             _setup = setup;
  56.             
  57.             var tf:TextField = new TextField();
  58.             tf.defaultTextFormat = new TextFormat('Helvetica', size, textColor, true);
  59.             tf.autoSize = TextFieldAutoSize.LEFT;
  60.             tf.text = buttonLabel;
  61.             
  62.             bd = new BitmapData(tf.width+TAIL_LENGTH, tf.height, true, bgColor+(0xff<<24));
  63.             bd.lock();
  64.             bd.fillRect(new Rectangle(tf.width,0,TAIL_LENGTH,tf.height),0x0);
  65.             bd.draw(tf);
  66.             
  67.             var prev:Particle = particles = new Particle();
  68.             var p:Particle;
  69.             
  70.             for (var i:int=0; i < tf.width; i++) {
  71.                 for (var j:int=0; j < tf.height; j++) {
  72.                     var color:uint = bd.getPixel(i, j);
  73.                     if ( color != bgColor ) {
  74.                         p = new Particle();
  75.                         p.x = i;
  76.                         p.y = j;
  77.                         p.sx = (Math.random()+1)*(i+1)*200 + DISTANCE;
  78.                         p.sy = p.y;
  79.                         p.cx = p.sx;
  80.                         p.cy = p.sy;
  81.                         p.vx = 2 + Math.random()*i/200;
  82.                         p.vy = 2;
  83.                         p.color = color;
  84.                         prev.next = p;
  85.                         prev = p;
  86.                         pnum++;
  87.                     } else {
  88.                         bd.setPixel32(i, j, 0x0);
  89.                     }
  90.                 }
  91.             }
  92.             bd.unlock();
  93.             
  94.             if( _setup ) {
  95.                 addChild( new Bitmap( bd ) );
  96.                 initEvent();
  97.             }
  98.         }
  99.         
  100.         private function initEvent():void
  101.         {
  102.             var over:Sprite = new Sprite();
  103.             over.graphics.beginFill(0x0, 0);
  104.             over.graphics.drawRect(0,0,bd.width,bd.height);
  105.             over.graphics.endFill();
  106.             addChild( over );
  107.             
  108.             over.addEventListener( MouseEvent.MOUSE_OVER, clickHandler );
  109.         }
  110.         
  111.         public function appearMotion():void
  112.         {
  113.             if( !_setup ) {
  114.                 bd.fillRect(bd.rect,0x0);
  115.                 addChild( new Bitmap( bd ) );
  116.                 initEvent();
  117.             }
  118.             motion();
  119.         }
  120.         
  121.         private function clickHandler(e:Event):void
  122.         {
  123.             motion();
  124.         }
  125.         
  126.         private function motion():void
  127.         {
  128.             var p:Particle = particles;
  129.             while((p = p.next) != null) {
  130.                 p.cx = p.sx;
  131.                 p.cy = p.sy;
  132.             }
  133.             if( !hasEventListener( Event.ENTER_FRAME ) ) {
  134.                 addEventListener( Event.ENTER_FRAME, update );
  135.             }
  136.         }
  137.         
  138.         private function update(e:Event):void
  139.         {
  140.             var num:int = 0;
  141.             var p:Particle = particles;
  142.             bd.lock();
  143.             bd.fillRect(bd.rect, 0x0);
  144.             
  145.             while((p = p.next) != null) {
  146.              var r:Number = Math.sqrt((p.x-p.cx)*(p.x-p.cx) + (p.y-p.cy)*(p.y-p.cy));
  147.                 p.cx += (p.x - p.cx )/p.vx;
  148.                 p.cy += (p.y - p.cy )/p.vy;
  149.                 if ( Math.abs( p.cx - p.x ) <= 1 && Math.abs( p.cy - p.y) <= 1) {
  150.                     p.cx = p.x;
  151.                     p.cy = p.y;
  152.                     num++;
  153.                 }
  154.                 var a:uint = r < APPEAR_RANGE ? (1-r/APPEAR_RANGE)*255 : 0;
  155.                 var c:uint = p.color + (a << 24);
  156.                 bd.setPixel32(p.cx, p.cy, c);
  157.             }
  158.             bd.unlock();
  159.             if(pnum == num) {
  160.                 e.target.removeEventListener(Event.ENTER_FRAME,arguments.callee);
  161.             }
  162.         }    
  163.     }
  164. class Particle 
  165. {
  166.     public var color:int;
  167.     public var x:Number;
  168.     public var y:Number;
  169.     public var cx:Number;
  170.     public var cy:Number;
  171.     public var sx:Number;
  172.     public var sy:Number;
  173.     public var vx:Number;
  174.     public var vy:Number;
  175.     public var next:Particle;
  176.     
  177.     public function Particle()
  178.     {
  179.         
  180.     }
  181. }
noswf
Get Adobe Flash Player