Skip to main content
Participating Frequently
March 11, 2016
Answered

Add symbol to stage based on symbols string

  • March 11, 2016
  • 2 replies
  • 698 views

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)

  }

This topic has been closed for replies.
Correct answer Ned Murphy

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? 

2 replies

Ned Murphy
Legend
March 11, 2016

Is HealthDrop the class name that you have assigned to this object in the library using the Properties panel?

Participating Frequently
March 11, 2016

Yes

I changed the code but nothing different has happened.

Ned Murphy
Ned MurphyCorrect answer
Legend
March 11, 2016

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? 

Ned Murphy
Legend
March 11, 2016

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;