Skip to main content
Inspiring
January 9, 2013
Answered

Calling a variable inside a movieClip.

  • January 9, 2013
  • 1 reply
  • 841 views

Hi. I'm having problems in calling my variable score which I assigned inside a movieClip. What I want to happen is when my score reaches my desired value(e.g. 10), I want the congratulations screen to be visible. The congratulations screen is placed in the main timeline. Is there a way I can access the variable that I created inside a movieClip?

I tried using:

if (score == 10)

{

MovieClip(root).screen_1.visible = true;

}

// this code snippet is placed inside the movieClip where the variable score is declared. But it doesn't seem to work.

I also tried:

if (MovieClip(root).score == 1)

{

screen_1.visible = true;

}

//this code snippet is placed in the main timeline.  It also didn't work. I didn't get any errors in this codes but it doesn't give me the result that I wanted. Thank you.

This topic has been closed for replies.
Correct answer kglad

i assume the congratulations screen is on the same timeline as the code you showed.

in that situation, you should be using MovieClip(root).score to reference score defined on the main timeline.  in addition, that code needs to execute everything score is updated so put that code in a function and call that function each time score is updated.

1 reply

kglad
Community Expert
Community Expert
January 9, 2013

where is score updated?

does you if-statement execute each time score is updated?

Inspiring
January 9, 2013

The score is updated in the main timeline. I also used the MovieClip(root) for that. No. I think the if statement doesn't not execute because the congratulations screen won't shot up. >.<

kglad
Community Expert
kgladCommunity ExpertCorrect answer
Community Expert
January 9, 2013

i assume the congratulations screen is on the same timeline as the code you showed.

in that situation, you should be using MovieClip(root).score to reference score defined on the main timeline.  in addition, that code needs to execute everything score is updated so put that code in a function and call that function each time score is updated.