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

Calling a variable inside a movieClip.

Explorer ,
Jan 09, 2013 Jan 09, 2013

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.

TOPICS
ActionScript
770
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

Community Expert , Jan 09, 2013 Jan 09, 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.

Translate
Community Expert ,
Jan 09, 2013 Jan 09, 2013

where is score updated?

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

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 ,
Jan 09, 2013 Jan 09, 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. >.<

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 Expert ,
Jan 09, 2013 Jan 09, 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.

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 ,
Jan 09, 2013 Jan 09, 2013

it works now! thank you for the help.

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 Expert ,
Jan 09, 2013 Jan 09, 2013
LATEST

you're welcome.

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