[COLOR=#000000][FONT=verdana]I am making my very first AS3 game, and though it’s quite simple I’m having trouble setting up a scoring system.[/FONT][/COLOR]
[COLOR=#000000][FONT=verdana]The concept of the game is simple. Objects appear on the screen, clicking the objects adds points. For this project I am working with 3 AS files, a Document class and two movieclip class files. I would also like to track how many objects have been added to the stage in addition to the score which should track how many objects have been clicked.[/FONT][/COLOR]
[COLOR=#000000][FONT=verdana]Here is my Doc Class[/FONT][/COLOR]
[COLOR=#000000][FONT=verdana]ActionScript Code:
[LEFT]package {
import flash.display.MovieClip;
import flash.display.Stage;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.text.TextField;
import VegeDoc.tomato;
import VegeDoc.carrot;
public class VegeDoc extends MovieClip {
public var tims:Timer = new Timer(1500, 1);
public var score_txt:TextField = new TextField;
public var myScore:Number = 0;
public var createTomato:Timer;
public var createCarrot:Timer;
public function VegeDoc() {
// constructor code
var newTom:VegeDoc.tomato = new tomato();
stage.addChild(newTom);
var newCarrot:VegeDoc.carrot = new carrot();
stage.addChild(newCarrot);
createTomato = new Timer(1000);
createTomato.addEventListener(TimerEvent.TIMER, sendTomato);
createTomato.start();
createCarrot = new Timer(1000);
createCarrot.addEventListener(TimerEvent.TIMER, sendCarrot);
createCarrot.start();
tims.addEventListener(TimerEvent.TIMER_COMPLETE, sendTomato);
tims.start();
}
public function sendTomato(e:Event) {
var t2 = new tomato();
stage.addChild(t2);
}
public function sendCarrot(e:Event) {
var c2 = new carrot();
stage.addChild(c2);
}
public function onClick(e:MouseEvent):void
{
score_txt.text = String(myScore+10); }
}
}
[/LEFT]
[/FONT][/COLOR]
[COLOR=#000000][FONT=verdana]This is one movie clip class (they are both identical, except class names)[/FONT][/COLOR]
[COLOR=#000000][FONT=verdana]ActionScript Code:
[LEFT]package VegeDoc {
import flash.display.MovieClip;
import flash.events.Event;
import flash.events.MouseEvent;
import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.text.TextField;
import flash.utils.getDefinitionByName;
import flash.display.DisplayObject;
import flash.display.DisplayObjectContainer;
public class tomato extends MovieClip
{
public var speed:Number;
public var timmy:Timer = new Timer(50,0);
public var xSpeed: Number = -7;
public var ySpeed: Number = -3;
public var score_txt:TextField = new TextField;
public var myScore:Number = 0;
public function tomato(){
this.x = Math.random();
this.y = Math.random()*800;
speed = Math.random()*10 + 5;
addEventListener(Event.ENTER_FRAME, moveTomato, false, 1, true);
addEventListener(MouseEvent.CLICK, clickTomato, false, 2, true);
addEventListener(MouseEvent.CLICK, onClick, false, 0, true);
}
public function moveTomato(e:Event):void{
var mc:MovieClip = MovieClip(e.target);
mc.x += mc.speed;
if(mc.x < -2000 || mc.x > (this.stage.stageWidth + 12000)){
mc.removeEventListener(Event.ENTER_FRAME, moveTomato);
mc.removeEventListener(MouseEvent.CLICK, clickTomato);
mc.stage.removeChild(mc);
}
}
public function clickTomato(e:MouseEvent):void{
var mc:MovieClip = MovieClip(e.target);
mc.removeEventListener(Event.ENTER_FRAME, moveTomato);
mc.removeEventListener(MouseEvent.CLICK, clickTomato);
mc.parent.removeChild(mc);
}
public function onClick(e:MouseEvent):void
{
score_txt.text = String(myScore+=10);
trace (String(myScore));
}
}
}
[/LEFT]
[/FONT][/COLOR]
[COLOR=#000000][FONT=verdana]Any help is greatly appreciated, I’ve been stuck on this for a couple days now.[/FONT][/COLOR]