1)Currently have this problem of unable to stop spawn for my project.
For loop has been inserted to serve its purpose but still no results appeared. I wan to make the spawn stop right after the clock goes to zero, and go to the next frame which is frame 2
Hope someone can help me with the spawn problem.
2)Currently i need to set a method or function that can help me make the monkey face from maybe the sickness level of 10 up 1 level to 9 when correct objects has been clicked on which i dunno.
Hope someone can help me with this reverse running of frames problem because i set the frames with names to run using array but do not know how to reverse the order of running.
Panel Code(Main):
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.text.*;
import flash.utils.Timer;
public class Panel extends MovieClip
{
private var clickScore:Number = 0;
private var count:uint;
private var prevCount:uint;
private var timer:Timer;
public var hpbar = new Healthbar(820,370);
public var mkface = new Monkeyface(300,300);
public function Panel ()
{
setting ();
}
public function setting ()
{
var edible:Edible = new Edible();
edible.x = Math.random() * stage.stageWidth;
edible.y = Math.random() * stage.stageHeight;
stage.addChild (edible);
count++;
var inedible:Inedible = new Inedible();
inedible.x = Math.random() * stage.stageWidth;
inedible.x = Math.random() * stage.stageHeight;
stage.addChild (inedible);
count++;
stage.addEventListener (MouseEvent.CLICK, clickon);
timer = new Timer(8000);
timer.addEventListener (TimerEvent.TIMER, addOn);
timer.start ();
var score:int = 0;
txtScore.text = clickScore.toString();
var countTime:Number = 10;
var myTimer:Timer = new Timer(1000,countTime);
myTimer.addEventListener (TimerEvent.TIMER, countdown);
myTimer.start ();
function countdown (event:TimerEvent):void
{
txtTimer.text = String((countTime) - myTimer.currentCount + "s");
}
if (txtTimer.text == "0")
{
myTimer.stop ();
txtTimer.text = String((countTime) - myTimer.currentCount + "s");
gotoAndPlay (2);
}
else
{
gotoAndPlay (3);
}
stage.addChild (hpbar);
addChild (mkface);
}
private function clickon (e:MouseEvent)
{
if (e.target is Edible)
{
e.target.die ();
clickScore += 10;
txtScore.text=String(clickScore);
}
if (e.target is Inedible)
{
e.target.die ();
clickScore-=10;
txtScore.text=String(clickScore);
hpbar.minusHealth ();
mkface.minusFace ();
}
}
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++)
{trace("asdasdasd");
var edible:Edible = new Edible();
edible.name="edible"+i;
edible.x=Math.random()*stage.width;
edible.y=Math.random()*stage.height;
addChild (edible);
var inedible:Inedible = new Inedible();
inedible.name="inedible"+i;
inedible.x=Math.random()*stage.width;
inedible.y=Math.random()*stage.height;
addChild (inedible);
} removeChild(inedible);trace("123123123123123123123123123");
}
public function spawnUp ()
{trace("123123123123123123");
if (numChildren>20)
{
timer.stop ();
var i:uint=numChildren;
while (i--)
{
removeChildAt(i);
gotoAndPlay(3);
}
}
}
}
}
Healthbar Code:
package
{
import flash.display.MovieClip;
import flash.events.*;
public class Healthbar extends MovieClip
{
public static const health1 : String = "minusone";
public static const health2 : String = "minustwo";
public static const health3 : String = "minusthree";
public static const health4 : String = "minusfour";
public static const health5 : String = "minusfive";
public static const health6 : String = "minussix";
public static const health7 : String = "minusseven";
public static const health8 : String = "minuseight";
public static const health9 : String = "minusnine";
public static const health10 : String = "minusten";
public static const healthArray : Array = new Array(health1, health2, health3, health4, health5, health6, health7, health8, health9, health10);
public function Healthbar(xPos : Number, yPos : Number)
{
this.x = xPos;
this.y = yPos;
}
public function minusHealth()
{
try
{
for (var x : uint = 0;x < healthArray.length;x++)
{
if (this.currentLabel == Healthbar.healthArray[x])
{
this.gotoAndPlay(healthArray[x]);
trace(healthArray[x]);
return;
}
if (Healthbar.healthArray[x]==healthArray.health10)
{
gotoAndPlay(2);
}
}
}
catch(Er : Error)
{
trace("error" + Er.message);
}
}
}
}
Edible Code(Spawn Object):
package
{
import flash.display.MovieClip;
import flash.events.*;
public dynamic class Edible extends MovieClip
{
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));
}
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 Code:
package
{
import flash.display.MovieClip;
import flash.events.*;
public dynamic class Inedible extends MovieClip
{
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));
}
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);
}
public function gone(e : Event):void
{
parent.removeChild(this);
}
}
}
Monkey face Happy to Sick Code(face changes):
package
{
import flash.display.MovieClip;
import flash.events.*;
public class Monkeyface extends MovieClip
{
public static const face1:String = "faceone";
public static const face2:String = "facetwo";
public static const face3:String = "facethree";
public static const face4:String = "facefour";
public static const face5:String = "facefive";
public static const face6:String = "facesix";
public static const face7:String = "faceseven";
public static const face8:String = "faceeight";
public static const face9:String = "facenine";
public static const face10:String = "faceten";
public static const faceArray:Array = new Array(face1,face2,face3,face4,face5,face6,face7,face8,face9,face10);
public function Monkeyface (xPos:Number, yPos:Number)
{
this.x = xPos;
this.y = yPos;
}
public function minusFace ()
{
try
{
for (var x : uint = 0; x < faceArray.length; x++)
{
if (this.currentLabel == Monkeyface.faceArray[x])
{
this.gotoAndPlay (faceArray[x]);
trace(faceArray[x]);
return;
}
}
if (Monkeyface.faceArray[x]==faceArray.face10)
{
gotoAndPlay(2);
}
}
catch (Er:Error)
{
trace ("error" + Er.message);
}
}
}
}
Main stage file is too big to be uploaded…
Hope someone can help me out.
I will send the main stage fla file if needed thanks alot.