flash on 2011-4-2
♥0 |
Line 57 |
Modified 2011-04-03 15:37:31 |
MIT License
archived:2017-03-20 03:26:17
ActionScript3 source code
/**
* Copyright points ( http://wonderfl.net/user/points )
* MIT License ( http://www.opensource.org/licenses/mit-license.php )
* Downloaded from: http://wonderfl.net/c/9xxR
*/
package {
import flash.events.Event;
import flash.text.TextField;
import flash.display.Sprite;
public class FlashTest extends Sprite {
private var tf:TextField;
private var time:int=0;
public function FlashTest() {
tf=new TextField();
tf.text="Hello World!";
tf.textColor=0xff0000;
tf.x=200
tf.y=100;
this.addChild(tf);
//
this.addEventListener(Event.ENTER_FRAME,loop);
}
private function loop(e:Event):void{
if(time==10){
var ball:Ball=new Ball(10+20*Math.random(),Math.random()*0xffffff);
ball.x=450*Math.random();
this.addChild(ball);
time=0;
}else{
time++
}
}
}
}
import flash.events.Event;
import flash.display.Shape;
class Ball extends Shape{
public var vy:Number=1;
public var life:int=0
public function Ball(rad:Number,col:int){
this.graphics.beginFill(col);
this.graphics.drawCircle(0,0,rad);
this.graphics.endFill();
this.addEventListener(Event.ENTER_FRAME,move);
}
public function move(event:Event):void{
vy+=0.98;
this.y+=vy;
if(this.y>=450){
this.y=450;
if(Math.abs(vy)<0.1){
vy=0;
}else{
vy*=-0.75;
}
}
life++;
if(life>300){//自壊
this.removeEventListener(Event.ENTER_FRAME,move);
parent.removeChild(this);
}
}
}