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

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

New Here ,
Nov 17, 2013 Nov 17, 2013

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?

TOPICS
ActionScript
1.1K
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 ,
Nov 17, 2013 Nov 17, 2013

What is  endscreen_mc.highscore_txt ?  Is it a 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
New Here ,
Nov 17, 2013 Nov 17, 2013

Yes, it's a text field. My last conditional was incorrectly typed..it's really "else if(endscreen_mc.highscore_txt == 100)  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
LEGEND ,
Nov 17, 2013 Nov 17, 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;

}

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
New Here ,
Nov 17, 2013 Nov 17, 2013

I tried doing that, but it still didn't work..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);

          }

  

}

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 ,
Nov 17, 2013 Nov 17, 2013

Try pputting a trace in that function to make sure it is getting called when you expect it should.  If this is anything like yesterday's issue, you might not be calling that function at all.

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
New Here ,
Nov 17, 2013 Nov 17, 2013

Well the trace statements are working, but it's just that the value is really 111, but it's thinking that it's less than 100..so it's calling on a wrong conditional for some reason

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 ,
Nov 17, 2013 Nov 17, 2013

Have you traced the value you think is 111?

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
New Here ,
Nov 17, 2013 Nov 17, 2013

Yes. Flash seems to think my highscore_txt value on a different layer, is 0. The highscore_txt is a dynamic layer and populates when the game is finished.

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
New Here ,
Nov 17, 2013 Nov 17, 2013
LATEST

Would get the value placed inside the shared object work? If so, how do you do that?

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 ,
Nov 17, 2013 Nov 17, 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)

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
New Here ,
Nov 17, 2013 Nov 17, 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);

          }

  

}

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