Basically i need help with this 2 sets of codings to make the object fly at random places but instead it does not fly but blink instead.
Food is the object i wan to make it move and
123 is the main class.
Food Codes:
package
{
import flash.display.MovieClip;
import flash.events.*;
public dynamic class Food extends MovieClip
{
private var xSpeed:Number = Math.random() * 10;
private var ySpeed:Number = Math.random() * 10;
public function Food()
{
this.addEventListener(Event.ENTER_FRAME, scurry);
this.gotoAndStop(Math.ceil(Math.random()*4));
}
public function scurry (e:Event)
{
if (this.x < 0 || this.x > 550)
{
this.xSpeed *= -1;
}
if (this.y < 0 || this.y > 400)
{
this.ySpeed *= -1;
}
this.x += this.xSpeed;
this.y += this.ySpeed;
}
public function die()
{
this.removeEventListener(Event.ENTER_FRAME, scurry);
parent.removeChild(this);
}
}
}
123 Codes:
package
{
import flash.display.Sprite;
import flash.events.;
import flash.utils.Timer;
import flash.text.;
public class 123 extends Sprite
{
private var count:uint;
private var prevCount:uint;
private var timer:Timer;
private var scoreText:TextField;
private var score:uint;
public function 123 ()
{
init();
}
private function init():void
{
var food:Food = new Food();
food.x = Math.random() * stage.stageWidth;
food.y = Math.random() * stage.stageHeight;
addChild(food);
count ++;
stage.addEventListener(MouseEvent.MOUSE_DOWN, kill);
timer = new Timer(5000);
timer.addEventListener(TimerEvent.TIMER, addFoods);
timer.start();
scoreText = new TextField();
scoreText.x = 500;
scoreText.y = 10;
scoreText.width = 200;
addChild(scoreText);
}
private function kill (e:MouseEvent):void
{
if(e.target is Food)
{
e.target.die();
score += 10;
scoreText.text = score.toString();
}
}
private function addFoods(e:TimerEvent)
{
prevCount = count;
count += count;
for (var i:uint = prevCount; i < count; i++)
{
var food:Food = new Food();
food.name = "food" + i;
food.x = Math.random() * stage.width;
food.y = Math.random() * stage.height;
addChild(food);
}
infested();
}
private function infested()
{
if (numChildren > 250)
{
timer.stop();
var i:int = this.numChildren;
while(i--)
{
removeChildAt(i);
}
addChild(scoreText);
}
}
}
}