I’m creating a shooting gallery, and I have most of it functioning, but the counter which is in it own class named “Board” is the problem. I have a main, ducks and board class. I’m trying to get the counter (board) to count down each time a duck is shot, so it’ll start from 8 ducks; shoot one, and it’ll count down to 7, 6, 5 … etc. The board graphic made in flash is place in the upper right corner. After all of the ducks are gone a sign will pop up saying"You Win"
package
{
import flash.display.Sprite;
import flash.events.Event;
import flash.events.MouseEvent;
[SWF(width="800", height="600", backgroundColor="#E6FCFF")]
public class Main extends Sprite
{
private var _sittingDucks:Array = []; //always set your arrays with [] at the top
private var couter:TextField;
public function Main()
{
//adding the background, and positioning it
var background:Background = new Background();
this.addChild(background);
background.x = 30;
background.y = 100;
for(var i:uint = 0; i < 5; i++)
{
//adding the first cloud, and positioning it
var clouds:Clouds = new Clouds();
this.addChild(clouds);
clouds.x = 130 + Math.random() * 600; //130 to 730
clouds.y = 230;
clouds.speedX = Math.random() * 3;
clouds.width = clouds.height = 200 * Math.random()//randomly changes the clouds demensions
}
var waves:Waves = new Waves();
this.addChild(waves);
waves.x = 0;
waves.y = 510;
waves.speedX = Math.random() * 3;
for(var j:uint = 0; j < 8; j++)
{
var ducks:Ducks = new Ducks();
this.addChild(ducks);
ducks.x = 100 + j * 100;
ducks.y = 475;
_sittingDucks.push(ducks);
ducks.addEventListener(MouseEvent.CLICK, ducksDestroy);
}
var waves2:Waves = new Waves();
this.addChild(waves2);
waves2.x = 0;
waves2.y = 520;
waves2.speedX = Math.random() * 3;
var setting:ForeGround = new ForeGround();
this.addChild(setting);
setting.x = 0;
setting.y = 50;
setting.width = 920;
var board:Board = new Board();
this.addChild(board);
board.x = 570;
board.y = 35;
}
private function ducksDestroy(event:MouseEvent):void
{
//store the crow we clicked on in a new array
var clickedDuck:Ducks = Ducks(event.currentTarget);
//remove it from the crows array
//find the address of the crow we are removing
var index:uint = _sittingDucks.indexOf(clickedDuck);
//remove it from the array with splice
_sittingDucks.splice(index, 1);
//remove it from my document's display list
this.removeChild(clickedDuck);
trace(_sittingDucks.length)
}
}
}
package
{
import flash.events.Event;
import flash.events.MouseEvent;
public class Ducks extends DuckBase
{
public var speedX:Number = 5;
public function Ducks()
{
super();
this.addEventListener(Event.ENTER_FRAME, moveDucks);
this.stop();
this.buttonMode = true;
}
private function moveDucks(event:Event):void
{
var d:DuckBase = DuckBase(event.currentTarget); //so we don't have to use the full event name
this.x += speedX;
if(this.x > 800) //starts from left at 800
{
this.x = 0; // drops down and loops once hitting 0
}
}
}
}
package
{
import flash.events.Event;
import flash.events.MouseEvent;
public class Board extends ScoreDisplayBase
{
private var sittingDucks:Array = [];
public function Board()
{
super();
//this.addEventListener(MouseEvent.CLICK, onClick);
}
//private function onClick(event:MouseEvent):void
{
//this.board = sittingDucks.length
}
}
}