Hi I was wondering if anyone can help!?
I am trying to make a game with boxes (gifts), flying across the screen randomly, they are worth 10pnts and when the user clicks one, more are supposed to enter the screen and then the game times out.
At the moment I can only get the first box on screen, but no more???
Any help would be appreciated!
package
{
import flash.display.Sprite;
import flash.utils.Timer;
import flash.text.;
import flash.events.;
import Gift;
public class Easymind extends Sprite
{//Class Definition
private var timer:Timer;
private var count:uint;
private var prevCount:uint;
public var score:uint;
public var scoreText:TextField;
public function Easymind () //Constructor function
{
init();
}
private function init():void
{
scoreText = new TextField();
scoreText.x = 500;
scoreText.y = 10;
scoreText.width = 20;
addChild(scoreText);
var gift:Gift = new Gift(score, scoreText);
gift.x = Math.random() * stage.stageWidth; // is the same as (0 to 0.99) * 550
gift.y = Math.random() * stage.stageHeight; // is the same as (0 to 0.99) * 576
addChild(gift);
timer = new Timer(1000);
timer.addEventListener(TimerEvent.TIMER, addGift);
timer.start();
}
private function addGift(eTimerEvent)
{
prevCount = count;
count += count;
for (var i:uint = prevCount; i < count; i++);
{
var gift:Gift = new Gift(score, scoreText);
gift.name = "gift" + i;
gift.x = Math.random() * stage.stageWidth; // is the same as (0 to 0.99) * 550
gift.y = Math.random() * stage.stageHeight; // is the same as (0 to 0.99) * 576
}
}
private function giftShower()
{
if (this.numChildren > 250)
{
timer.stop();
var i:int = this.numChildren;
while(i--)
{
removeChildAt(i);
}
addChild(scoreText);
}
}
}
}
[COLOR=Red]// then in my second packageā¦[/COLOR]
package
{
import flash.display.MovieClip;
import flash.events.;
import flash.utils.Timer;
import flash.text.;
import Gift;
public dynamic class Gift extends MovieClip
{
private var dx:Number = Math.random() * 10; // make gift scurry
private var dy:Number = Math.random() * 10;
public var newscore:uint;
public var newscoreText:TextField;
public function Gift (score, scoreText)
{
this.gotoAndStop(Math.ceil(Math.random() * 4));
this.addEventListener(Event.ENTER_FRAME, scurry);
this.addEventListener(MouseEvent.MOUSE_DOWN, kill);
newscore = score;
newscoreText = scoreText;
}
public function scurry (e:Event)
{
if (this.x < 0 || this.x > 550)
{
this.dx *= -1;
}
if (this.y < 0 || this.y > 576)
{
this.dy *= -1;
}
this.x += this.dx; // make gift scurry
this.y += this.dy;
}
public function die ()
{
this.removeEventListener(Event.ENTER_FRAME, scurry);
parent.removeChild(this);
}
public function kill (e:MouseEvent):void
{
trace(e.target);
if(e.target is Gift)
{
newscore += 10;
newscoreText.text = newscore.toString();
e.target.die();
}
}
}
}