Flashの宝石箱やー _wonder forked:0favorite:2lines:52license : MIT License modified : 2010-01-05 20:17:46 Embed Tweet package { import flash.display.Sprite; import flash.events.*; [SWF( width="465", height="465", backgroundColor="0x000000", frameRate="30" )] public class Jewel extends Sprite { public function Jewel() { stage.addEventListener(Event.ENTER_FRAME, make_ball); } private function make_ball(e:Event):void { var ball:Ball = new Ball(); ball.x = stage.mouseX; ball.y = stage.mouseY; ball.init(); ball.move(); addChild( ball ); } } } import flash.display.*; import flash.events.*; internal class Ball extends Sprite { private var ball:Sprite; private var radius:Number = 5; private var g:Number = Math.random()+0.2; private var speed:Number = -10; private var color:int = Math.random()*0xFFFFFF; private var perX:Number = Math.random()*10-5; public function init():void { ball = new Sprite(); ball.graphics.lineStyle(1,color); ball.graphics.beginFill(color,0.2); ball.graphics.drawCircle(0,0,5); ball.graphics.endFill(); addChild( ball ); } public function move():void { addEventListener(Event.ENTER_FRAME, fall); } public function move_stop():void { removeEventListener(Event.ENTER_FRAME, fall); } private function fall(e:Event):void { speed += g; this.y += speed; this.x += perX; if(this.y > stage.stageHeight+radius){ move_stop(); var parentObj:Object = Object(parent); parentObj.removeChild(this); } } } Code Fullscreen Preview Fullscreen 見た目上は消えてるけどBallインスタンスはaddChildされたまんまじゃあ・・ by uwi at 2010/01/05 19:37:37 そうなんです!自分自身をremoveする方法がわかんなくて。 ちょっと直したんですが、これでよいのですかね・・・。 by _wonder at 2010/01/05 20:19:18 お、よさげ by uwi at 2010/01/08 17:29:03 qwertyui chamadi color mouseY mouseX removeEventListener Object removeChild parent Event.ENTER_FRAME drawCircle addChild addEventListener endFill beginFill lineStyle Event stageHeight Math.random Sprite int Number