Copy link to clipboard
Copied
im making a game and i have occured a problem.i have a hits text on the screen and every time a enemys bullet hits me it decrases by 1.and i wanna make that when it gets to 0 my ship explodes.
Dont know how to do it.tryed this
package com.asgamer.basics1
{
import flash.display.MovieClip;
import flash.display.Stage;
import flash.text.TextField;
import flash.events.Event;
public class ScoreHUD extends MovieClip
{
private var stageRef:Stage;
public var s_score:Number = 0;
public var s_hits:Number = 100;
public var s_kills:Number = 0;
public function ScoreHUD(stageRef:Stage)
{
this.stageRef = stageRef;
kills.text = "0";
hits.text = "100";
score.text = "0";
x = 10;
y = stageRef.stageHeight - height - 10;
}
public function updateKills(value:Number) : void
{
s_kills += value;
kills.text = String(s_kills);
}
public function updateHits(value:Number) : void
{
s_hits += value;
hits.text = String(s_hits);
}
public function updateScore(value:Number) : void
{
s_score += value;
score.text = String(s_score);
}
public function loop(e:Event) : void{
if (hits.text = 0){stageRef.addChild(new SmallImplosion(stageRef, x, y));} // this is where i get the error
}
}
}
i get this error 1067: Implicit coercion of a value of type int to an unrelated type String.
Copy link to clipboard
Copied
use:
package com.asgamer.basics1 { import flash.display.MovieClip; import flash.display.Stage; import flash.text.TextField; import flash.events.Event; public class ScoreHUD extends MovieClip { private var stageRef:Stage; public var s_score:Number = 0; public var s_hits:Number = 100; public var s_kills:Number = 0; public function ScoreHUD(stageRef:Stage) { this.stageRef = stageRef; kills.text = "0"; hits.text = "100"; score.text = "0"; x = 10; y = stageRef.stageHeight - height - 10; } public function updateKills(value:Number) : void { s_kills += value; kills.text = String(s_kills); } public function updateHits(value:Number) : void { s_hits += value; hits.text = String(s_hits); } public function updateScore(value:Number) : void { s_score += value; score.text = String(s_score); } public function loop(e:Event) : void{ if (hits.text == "0"){stageRef.addChild(new SmallImplosion(stageRef, x, y));} // this is where i get the error } } }
Copy link to clipboard
Copied
no error now but nothing happens.Any help?
Copy link to clipboard
Copied
use the trace() function to see what's in your hits textfield. ie, make sure it's not html-enabled, kerning is disabled and its single line.