Copy link to clipboard
Copied
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.
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.
Copy link to clipboard
Copied
where is score updated?
does you if-statement execute each time score is updated?
Copy link to clipboard
Copied
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. >.<
Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
it works now! thank you for the help.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now