Copy link to clipboard
Copied
Hi,
I'm string to add a symbol to the stage based on a string value in an existing Symbol which is on the stage. I get no error when the game runs, but the symbol just doesn't spawn onto the stage. I have no idea why
This is the code:
//Variables used
var score:int = 0
var startX:int = stage.stageWidth = 920
var startY:int = stage.stageWidth = 475
//Check to see if 'score' is 350 in ScoreBoardDisplay.txtScore.text
if(ScoreBoardDisplay.txtScore.text == String(350))
{
var HD1 = new HealthDrop();
HD1.x = stage.stageWidth = startX
HD1.y = stage.stageHeight = startY
stage.addChild(HD1);
HealthDrops.push(HD1)
}
Assuming you are not entering this frame when you check the score, but are always there or at least hang around for awhile, the problem is that the conditional code you show is only going to execute once, immediately upon entering that frame. It does not sit there monitoring any change in the text field value. You have to tell the code to execute.
In this case what you could do is place that code inside a function that executes every time the textfield value is changed.
What code you you have fo
...Copy link to clipboard
Copied
var startX:int = stage.stageWidth = 920
var startY:int = stage.stageWidth = 475
Not that it is related, but tose two lines are contradictory... stageStageWidth is a property but you appear to be trying to change it at will, and using it loosely. I am guessing the second is meant to involve height, not width I recommend you do not use them as you do... either...
var startX:int = 920;
var startY:int = 475;
or
var startX:int = stage.stageWidth;
var startY:int = stage.stageHeight;
and
HD1.x = startX;
HD1.y = startY;
Copy link to clipboard
Copied
Is HealthDrop the class name that you have assigned to this object in the library using the Properties panel?
Copy link to clipboard
Copied
Yes
I changed the code but nothing different has happened.
Copy link to clipboard
Copied
Assuming you are not entering this frame when you check the score, but are always there or at least hang around for awhile, the problem is that the conditional code you show is only going to execute once, immediately upon entering that frame. It does not sit there monitoring any change in the text field value. You have to tell the code to execute.
In this case what you could do is place that code inside a function that executes every time the textfield value is changed.
What code you you have for changing the value in the textfield?
Copy link to clipboard
Copied
This is the code for updating the score. It's based on a Movie clip colliding with another Movie clip.
function enemyShellKilled():void
{
for (var i:int = 0; i <= shells.length - 1; i++)
{
for (var j:int = 0; j <= enemies.length - 1; j++)
{
for(var h:int = 0; i <= Hull.length - 1; i++)
if (shells.hitTestObject(enemies
stage.removeChild(enemies
stage.removeChild(shells);
stage.removeChild(Hull
enemies.splice(j, 1);
shells.splice(i, 1);
Hull.splice(h, 1);
score += 35; <<------------------------- This changes the score
stage.removeChild(Healthbars);
Healthbars.splice (i, 1);
ScoreBoardDisplay.txtScore.text = String(score)
}
}
}
}
Copy link to clipboard
Copied
for(var h:int = 0; i <= Hull.length - 1; i++)
I'm pretty sure you want to use h, not i.
Also, when you do this:
for(var h:int = 0; i <= Hull.length - 1; i++)
if (shells.hitTestObject(enemies
You're making the same hit test Hull.length times.
I'm pretty sure that's not what you want to do...
Copy link to clipboard
Copied
sry about the code. I was handed this as an assignment for my college coursework. I didn't even get the option to lean AC3. I was just handed code and told to change it.
For this part, I was trying to stack each of the for statements into one like this:
for (var i:int = 0; i <= shells.length - 1; i++) && for (var j:int = 0; j <= enemies.length - 1; j++)
But it wouldn't work so I listed them like so, below.
And yes, that spelling error is my fault, ill change it.
function enemyShellKilled():void
{
for (var i:int = 0; i <= shells.length - 1; i++)
{
for (var j:int = 0; j <= enemies.length - 1; j++)
{
for(var h:int = 0; i <= Hull.length - 1; i++)
Copy link to clipboard
Copied
"For this part, I was trying to stack each of the for statements into one like this:
for (var i:int = 0; i <= shells.length - 1; i++) && for (var j:int = 0; j <= enemies.length - 1; j++)"
That just won't work... You can do this, though:
for (var i:int = 0, var j:int = 0; i <= shells.length - 1 && j <= enemies.length - 1; i++, j++)
But keep in mind the loop will stop as soon as one the indexes has reached the end of its array, even if the other one still has elements to be parsed.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now