Project has 3 frames :frontstage,middlestage,backstage.
when i first play the frontstage when execute with ctrl+enter, there is a movieclip
called startgame. When i click startgame, it would go to frame 2 is called middlestage.
there are objects for user to click.
when either the time goes to ZERO or the healthbar GOES to ZERO, it would then
go to the third frame called backstage.
Currently backstage have this movieclip called restart.
once i click restart, it will go back to first frame called frontstage.
problem:
1)Currently it does not go to frontstage and it only goes to middlestage.
even after i put gotoAndPlay(“frame name”);
2)when i restart game, it does not show the time.(meaning it does not resets to the time i set earlier and it starts at 0 which is the time that ended previosuly)
does anyone knows how to solve my problem??
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=0;
public var prevCount:uint;
public var timer:Timer;
public var hpbar = new Healthbar(630,370);
public var mkface = new Monkeyface(350,380);
public var sgo:startGameone = new startGameone();
public var countTime:Number = 5;
public var myTimer:Timer = new Timer(2000,countTime);
public var inedible:Inedible = new Inedible();
public var edible:Edible = new Edible();
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 var repeat:int = 0;
public function Panel()
{
stage.addChild(sgo);
sgo.addEventListener(MouseEvent.CLICK, sGame);
}
public function sGame(e:MouseEvent)
{
//if(e.target is startGameone)
gotoAndPlay("middlestage");
stage.removeChild(sgo);
stage.removeEventListener(MouseEvent.CLICK, sGame);
stage.addEventListener(MouseEvent.CLICK , gameStartone);
}
public function setting ()
{
parent.addChild(mkface);
parent.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);
timer = new Timer(6000);
timer.start ();
timer.addEventListener (TimerEvent.TIMER, addOn);
var score:int = 0;
myTimer.start();
txtTimer.text = String((countTime) - myTimer.currentCount + "s");
myTimer.addEventListener (TimerEvent.TIMER, countdown);
timer.addEventListener (TimerEvent.TIMER, timerHandler);
}
public function timerHandler(event:TimerEvent)
{
if(txtTimer.text=="0")
{myTimer.addEventListener(TimerEvent.TIMER,timerHandler);
trace("reach");
repeat--;
txtTimer.text = String((countTime) - myTimer.currentCount + "s");
}
}
public function countdown (e:TimerEvent):void
{
txtTimer.text = String((countTime) - myTimer.currentCount + "s");
trace(String((countTime) - myTimer.currentCount + "s"));
if (txtTimer.text == "0s")
{
myTimer.stop();
parent.removeEventListener (MouseEvent.CLICK, clickon);
parent.removeChild(hpbar);
parent.removeChild(mkface);
gotoAndPlay ("backstage");
parent.addChild(gobg);
parent.addChild(msg);
parent.addChild(go);
parent.addChild(ta);
parent.addChild(nx);
//parent.removeChild(edible);
//parent.removeChild(inedible);
stage.addEventListener(MouseEvent.CLICK, restart);
trace("GAMEOVER");
}
}
public function restart(e:MouseEvent)
{
if(e.target is tryagain)
{
//stage.removeChild(mkface);
gotoAndPlay("middlestage");
stage.removeChild(ta);
stage.removeChild(go);
stage.removeChild(msg);
stage.removeChild(nx);
stage.removeChild(gobg);
trace("moving down.");
//txtTimer.text = String((countTime) - myTimer.currentCount + "s");
trace(String((countTime) - myTimer.currentCount + "s"));
}
}
public function gameStartone(event:MouseEvent)
{
if(event.target is startGameone)
{
gotoAndPlay("middlestage");
}
}
public function clickon (event:MouseEvent)
{
if (event.target is Edible)
{
event.target.die ();
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 (event.target is Inedible)
{
event.target.die ();
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;
//var len:int = deptControlArray.length;
//for(var count:int=0;count<len;count++)
for (var i:int = prevCount; i < count; i++)
{
if(i <= 8)
{
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 <= 8)
{
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
{
return;
}*/
}
for (var r:int = prevCount; r > count; r++)
{
if(r <= 5)
{
parent.removeChild(edible);
}
if(r <= 5)
{
parent.removeChild(inedible);
}
else
{
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");
}
}
}
*/
}
}