# Help on codes

**URL:** https://forum.kirupa.com/t/help-on-codes/310202
**Category:** flash
**Created:** [June 4, 2010, 2:05am UTC](https://forum.kirupa.com/t/help-on-codes/310202 "2010-06-04T02:05:48Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![punk123123123](https://avatars.discourse-cdn.com/v4/letter/p/9de0a6/32.png) [@punk123123123](https://forum.kirupa.com/u/punk123123123)
#### Post date: [June 4, 2010, 2:05am UTC](https://forum.kirupa.com/t/help-on-codes/310202/1 "2010-06-04T02:05:48Z")

</div>

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 &lt; 0 || this.x &gt; 550)
		{
			this.xSpeed *= -1;
		}
		
		if (this.y &lt; 0 || this.y &gt; 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 &lt; 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 &gt; 250)
		{
			timer.stop();
			
			var i:int = this.numChildren;
			while(i--)
			{
				removeChildAt(i);
			}
		
			addChild(scoreText);

		}
			
	}

}

```

}
