Currently i have this problem:
I have the timer to run to 0 before doing the if statement.
But now it does not even run the if statement…The problem function starts from this function — public function countdown (event:TimerEvent)
And the restart movieclip and the next movieclip does not work.
I am working in an OOP style of making this project.
Hope someone can help.
PANEL:
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
public class Panel extends MovieClip
{
public var clickScore:Number = 0;
public var count:uint;
public var prevCount:uint;
public var timer:Timer;
public var countTime:Number =10;
public var myTimer:Timer = new Timer(1000,countTime);
public var hpbar = new Healthbar(630,370);
public var mkface = new Monkeyface(350,380);
public var inedible:Inedible = new Inedible();
public var edible:Edible = new Edible();
public var sgo = new startGameone();
public var gobg:goBackground = new goBackground();
public var go:gameover = new gameover();
public var ta:tryagain = new tryagain();
public var msg:Message = new Message();
public var nx:Next = new Next();
public function Panel()
{
stage.addChild(sgo);
sgo.addEventListener(MouseEvent.CLICK, sGame);
}
public function sGame(e:MouseEvent)
{
//if(e.target is startGameone)
gotoAndPlay("game");
stage.removeChild(sgo);
stage.removeEventListener(MouseEvent.CLICK, sGame);
}
public function setting()
{
parent.addEventListener(MouseEvent.CLICK , sGame);
stage.addChild(mkface);
stage.addChild(hpbar);
edible.x = Math.random() * stage.stageWidth;
edible.y = Math.random() * stage.stageHeight;
parent.addChild(edible);
count++;
inedible.x = Math.random() * stage.stageWidth;
inedible.x = Math.random() * stage.stageHeight;
parent.addChild(inedible);
count++;
stage.addEventListener (MouseEvent.CLICK, clickon);
myTimer.start();
timer = new Timer(6000);
timer.start ();
timer.addEventListener (TimerEvent.TIMER, addOn);
var score:int = 0;
myTimer.addEventListener (TimerEvent.TIMER, countdown);
}
public function countdown (event:TimerEvent)
{
trace(String((countTime) - myTimer.currentCount + "s"));
txtTimer.text = String((countTime) - myTimer.currentCount +"s" );
//if(txtTimer.text == "0")
{trace("timeover");
myTimer.stop ();
stage.removeEventListener (MouseEvent.CLICK, clickon);
stage.removeChild(hpbar);
stage.removeChild(mkface);
gotoAndPlay ("GameOver");
stage.addChild(gobg);
stage.addChild(msg);
stage.addChild(go);
stage.addChild(ta);
stage.addChild(nx);
//removeall();
if(edible.exist == true)
{
stage.removeChild(edible);
trace("remove");
}
if(inedible.exist == true);
{
stage.removeChild(inedible);
}
stage.addEventListener(MouseEvent.CLICK, restart);
trace("GAMEOVER");
}
}
public function restart(e:MouseEvent)
{
if(e.target is tryagain)
{
gotoAndPlay("startGame");
}
}
/*
public function sGame(event:MouseEvent)
{
if(event.target is startGameone)
{
gotoAndPlay("startGame");
}
}
*/
public function clickon (e:MouseEvent)
{
if (e.target is Edible)
{
e.target.die ();
edible.exist=false;
hpbar.plusHealth();
if(mkface.currentLabel == "10face")
{
return mkface.currentLabel == "10face";
}
if(mkface.currentLabel == "9face")
{
mkface.gotoAndPlay("10face");
return;
}
if(mkface.currentLabel == "8face")
{
mkface.gotoAndPlay("9face");
return;
}
if(mkface.currentLabel == "7face")
{
mkface.gotoAndPlay("8face");
return;
}
if(mkface.currentLabel == "6face")
{
mkface.gotoAndPlay("7face");
return;
}
if(mkface.currentLabel == "5face")
{
mkface.gotoAndPlay("6face");
return;
}
if(mkface.currentLabel == "4face")
{
mkface.gotoAndPlay("5face");
return;
}
if(mkface.currentLabel == "3face")
{
mkface.gotoAndPlay("4face");
return;
}
if(mkface.currentLabel == "2face")
{
mkface.gotoAndPlay("3face");
return;
}
if(mkface.currentLabel == "1face")
{
mkface.gotoAndPlay("2face");
return;
}
}
if (e.target is Inedible)
{
e.target.die ();
inedible.exist=false;
mkface.minusFace();
if(hpbar.currentLabel == "10Health")
{
hpbar.gotoAndPlay("9Health");
return hpbar.currentLabel == "9Health";
}
if(hpbar.currentLabel == "9Health")
{
hpbar.gotoAndPlay("8Health");
return;
}
if(hpbar.currentLabel == "8Health")
{
hpbar.gotoAndPlay("7Health");
return;
}
if(hpbar.currentLabel == "7Health")
{
hpbar.gotoAndPlay("6Health");
return;
}
if(hpbar.currentLabel == "6Health")
{
hpbar.gotoAndPlay("5Health");
return;
}
if(hpbar.currentLabel == "5Health")
{
hpbar.gotoAndPlay("4Health");
return;
}
if(hpbar.currentLabel == "4Health")
{
hpbar.gotoAndPlay("3Health");
return;
}
if(hpbar.currentLabel == "3Health")
{
hpbar.gotoAndPlay("2Health");
return;
}
if(hpbar.currentLabel == "2Health")
{
hpbar.gotoAndPlay("1Health");
return;
}
}
}
public function addOn (e:TimerEvent)
{
prevCount=count;
count+=count;
for (var i:int = prevCount; i < count; i++)
{trace("add");
if(i <= 5) {
var edible:Edible = new Edible();
//edible.name="edible"+i;
edible.x=Math.random()*stage.width;
edible.y=Math.random()*stage.height;
parent.addChild(edible);
}
if(i <= 5) {
var inedible:Inedible = new Inedible();
//inedible.name="inedible"+i;
inedible.x=Math.random()*stage.width;
inedible.y=Math.random()*stage.height;
parent.addChild(inedible);
}
else
{trace("return+");
return;
}
if(edible.i >= 5) {trace("REMOVED")
//var edible:Edible = new Edible();
//edible.name="edible"+i;
//edible.x=Math.random()*stage.width;
//edible.y=Math.random()*stage.height;
parent.removeChild(edible);
}
if(inedible.i >= 5) {
//var inedible:Inedible = new Inedible();
//inedible.name="inedible"+i;
//inedible.x=Math.random()*stage.width;
//inedible.y=Math.random()*stage.height;
parent.removeChild(inedible);
}
else
{trace("return-");
return;
}
}
}
public function removeall ()
{
prevCount=count;
count+=count;
//var len:int = deptControlArray.length;
//for(var count:int=0;count<len;count++)
for (var i:int = prevCount; i < count; i--)
{
if(i >= 5) {trace("REMOVED")
var edible:Edible = new Edible();
//edible.name="edible"+i;
edible.x=Math.random()*stage.width;
edible.y=Math.random()*stage.height;
parent.removeChild(edible);
}
if(i >= 5) {
var inedible:Inedible = new Inedible();
//inedible.name="inedible"+i;
inedible.x=Math.random()*stage.width;
inedible.y=Math.random()*stage.height;
parent.removeChild(inedible);
}
else
{trace("returning");
return;
}
}
//return(edible);
//return(inedible);
}
/*
public function spawnUp ()
{
if(this.numChildren == 1)
{
timer.stop ();
stop();
var i:uint=numChildren;
while (i==-1)
{
removeChildAt(1);
gotoAndPlay("End");
}
}
}
*/
}
}
EDIBLE:
package
{
import flash.display.MovieClip;
import flash.events.*;
public dynamic class Edible extends MovieClip
{
public var exist:Boolean;
var xSpeed:Number = Math.random() * 4;
var ySpeed:Number = Math.random() * 4;
public function Edible()
{
this.addEventListener(Event.ENTER_FRAME, wobbally);
this.gotoAndStop(Math.ceil(Math.random()*4));
this.exist=true;
}
public function wobbally (e:Event)
{
if (this.x < 0 || this.x > 400)
{
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, wobbally);
parent.removeChild(this);
}
}
}
INEDIBLE:
package
{
import flash.display.MovieClip;
import flash.events.*;
public dynamic class Inedible extends MovieClip
{
public var exist:Boolean;
var xSpeed : Number = Math.random() * 4;
var ySpeed : Number = Math.random() * 10;
public function Inedible()
{
this.addEventListener(Event.ENTER_FRAME, wobbally);
this.gotoAndStop(Math.ceil(Math.random() * 4));
this.exist=true;
}
public function wobbally(e : Event) : void
{
if (this.x < 0 || this.x > 400)
{
this.xSpeed *= -1;
}
if (this.y < 0 || this.y > 400)
{
this.ySpeed *= -1;
}
this.x += this.xSpeed;
this.y += this.ySpeed;
}
public function die() : void
{
this.removeEventListener(Event.ENTER_FRAME, wobbally);
parent.removeChild(this);
}
}
}
MONKEYFACE:
package
{
import flash.display.MovieClip;
import flash.events.*;
public class Monkeyface extends MovieClip
{
public static const tenface:String = "10face";
public static const nineface:String = "9face";
public static const eightface:String = "8face";
public static const sevenface:String = "7face";
public static const sixface:String = "6face";
public static const fiveface:String = "5face";
public static const fourface:String = "4face";
public static const threeface:String = "3face";
public static const twoface:String = "2face";
public static const oneface:String = "1face";
public function Monkeyface (xPos:Number, yPos:Number)
{
this.x = xPos;
this.y = yPos;
}
public function minusFace()
{
if(this.currentLabel == tenface)
{
this.gotoAndPlay(nineface);
return this.currentLabel == nineface;
}
if(this.currentLabel == nineface)
{
this.gotoAndPlay(eightface);
return;
}
if(this.currentLabel == eightface)
{
this.gotoAndPlay(sevenface);
return;
}
if(this.currentLabel == sevenface)
{
this.gotoAndPlay(sixface);
return;
}
if(this.currentLabel == sixface)
{
this.gotoAndPlay(fiveface);
return;
}
if(this.currentLabel == fiveface)
{
this.gotoAndPlay(fourface);
return;
}
if(this.currentLabel == fourface)
{
this.gotoAndPlay(threeface);
return;
}
if(this.currentLabel == threeface)
{
this.gotoAndPlay(twoface);
return;
}
if(this.currentLabel == twoface)
{
this.gotoAndPlay(oneface);
return;
}
}
}
}
HEALTHBAR:
package
{
import flash.display.MovieClip;
import flash.events.*;
public class Healthbar extends MovieClip
{
public static const tenhp : String = "10Health";
public static const ninehp : String = "9Health";
public static const eighthp : String = "8Health";
public static const sevenhp : String = "7Health";
public static const sixhp : String = "6Health";
public static const fivehp : String = "5Health";
public static const fourhp : String = "4Health";
public static const threehp : String = "3Health";
public static const twohp : String = "2Health";
public static const onehp : String = "1Health";
public function Healthbar(xPos : Number, yPos : Number)
{
this.x = xPos;
this.y = yPos;
}
public function plusHealth()
{
if(this.currentLabel == tenhp)
{
return;
}
if(this.currentLabel == ninehp)
{
this.gotoAndPlay(tenhp);
return;
}
if(this.currentLabel == eighthp)
{
this.gotoAndPlay(ninehp);
return;
}
if(this.currentLabel == sevenhp)
{
this.gotoAndPlay(eighthp);
return;
}
if(this.currentLabel == sixhp)
{
this.gotoAndPlay(sevenhp);
return;
}
if(this.currentLabel == fivehp)
{
this.gotoAndPlay(sixhp);
return;
}
if(this.currentLabel == fourhp)
{
this.gotoAndPlay(fivehp);
return;
}
if(this.currentLabel == threehp)
{
this.gotoAndPlay(fourhp);
return;
}
if(this.currentLabel == twohp)
{
this.gotoAndPlay(threehp);
return;
}
if(this.currentLabel == onehp)
{
this.gotoAndPlay(twohp);
return;
}
}
}
}
There is another panel file in fla format that cant be upload due to the size…i hope someone out there can help me if you guys know anything.i Will send the file via email to u asap.