Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Add symbol to stage based on symbols string

Community Beginner ,
Mar 11, 2016 Mar 11, 2016

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)

  }

TOPICS
ActionScript
618
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Mar 11, 2016 Mar 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 fo

...
Translate
LEGEND ,
Mar 11, 2016 Mar 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;

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 11, 2016 Mar 11, 2016

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 11, 2016 Mar 11, 2016

Yes

I changed the code but nothing different has happened.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Mar 11, 2016 Mar 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? 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 11, 2016 Mar 11, 2016


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)

                }

            }

      }

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 11, 2016 Mar 11, 2016

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 12, 2016 Mar 12, 2016

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++)

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Explorer ,
Mar 12, 2016 Mar 12, 2016
LATEST

"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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines