Skip to main content
Known Participant
November 17, 2013
Question

How to make a movie clip invisible depending on a value in another layer?

  • November 17, 2013
  • 2 replies
  • 1107 views

I am trying to make an "achievements" page for my game, where if the user has a high score greater than 100, then the achievement can be unlocked. I tried using a code like this, but it didn't seem to work!

function Check();
if(endscreen_mc.highscore_txt > 100)
{
medals
.roachLock.visible = false;
}
else if(endscreen_mc.highscore_txt < 100)
{
medals
.roachLock.visible = true;
}
else if(endscreen_mc.visible == 100)
{
medals
.roachLock.visible = true;
}

The high score value is saved inside a shared object. What's wrong with my code, and what can I do to fix it?

This topic has been closed for replies.

2 replies

robdillon
Participating Frequently
November 18, 2013

Are you seeing any errors when you run that?

Is the instance name of the score text "highscore_txt? If thats's the case then you want to compare "endscreen_mc.highscore_txt.text". And you need to compare it to a string. Since you're comparing strings, you can't directly use a greater than - less than method of comparison. You'll have to convert the string in the textfield to a number to do the comparison.

if(Number(endscreen_mc.highscore_txt.text) > 100)

razer65Author
Known Participant
November 18, 2013

I tried doing this, but it's still not working.. 

function Check():void

{

if(Number(endscreen_mc.highscore_txt.text) > 100)

{

medals_mc.roachLock.visible = false;

medals_mc.medal_mc.visible = true;

}

else if(Number(endscreen_mc.highscore_txt.text) <= 100)

{

    medals.roachLock.visible = true;

}

}

This is what's inside my endscreen layer

function showresults():void

{

          Rchannel.stop();

   // display current score

   endscreen_mc.scoreR_txt.text = String(score);

   // calculate, display and save (if necessary) a new highscore

   var so:SharedObject = SharedObject.getLocal("alltimeHighScore");

   if (!so.data.score || score > so.data.score)

   {

       endscreen_mc.highscore_txt.text = String(score);

       so.data.score = score;

       so.flush();

             Check();

   }

   else

   {

       endscreen_mc.highscore_txt.text = String(so.data.score);

   }

   if(so.data.score==score)

          {

                    endscreen_mc.score_txt.text = String(score);

                    endscreen_mc.highscore_txt.text = String(score);

          }

  

}

Ned Murphy
Legend
November 18, 2013

What is  endscreen_mc.highscore_txt ?  Is it a textfield?

razer65Author
Known Participant
November 18, 2013

Yes, it's a text field. My last conditional was incorrectly typed..it's really "else if(endscreen_mc.highscore_txt == 100)  I

Ned Murphy
Legend
November 18, 2013

As Rob described, you need to compare the text property of the textfield and it has to be treated as a numeric value.

You don't need that third condition.  You can change the second one to be...

...

else if(Number(endscreen_mc.highscore_txt.text) <= 100)

{

    medals.roachLock.visible = true;

}