Skip to content

Instantly share code, notes, and snippets.

@donghee
Created March 20, 2011 08:46
Show Gist options
  • Save donghee/878208 to your computer and use it in GitHub Desktop.
Save donghee/878208 to your computer and use it in GitHub Desktop.
Falling stars
// api http://help.adobe.com/ko_KR/AS3LCR/Flash_10.0/
package {
import flash.utils.Timer;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.ui.Mouse;
public class Star extends Sprite {
[Embed(source='star.png')]
private var starClass:Class;
private var star:Bitmap = new starClass ();
private var timer:Timer = new Timer(1000);
public function Star() {
timer.addEventListener(TimerEvent.TIMER, onLoop);
timer.start();
}
private function onLoop(evt:Event):void {
var star:Bitmap = new starClass ();
star.height = 50;
star.width = 50;
addChild(star);
star.addEventListener(Event.ENTER_FRAME, fall);
star.x = Math.floor(Math.random() * stage.stageWidth);
}
private function fall(e:Event):void {
var x:Number = (0.5-Math.random()) * 2;
e.currentTarget.x += Math.sin(x) * 5;
e.currentTarget.y += Math.floor(Math.random() * 5);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment