Skip to main content
Participating Frequently
October 11, 2013
Question

Using MovieClip(root) Problem

  • October 11, 2013
  • 1 reply
  • 2670 views

im at frame 3.. i have text field on the stage name scoreTxt.. at frame 3 i added TryClass..

TryClass has function of updateScore..  so my code is

public function updateScore(amount:int):void

                    {

                              score += amount;

                              if(score < 0) score = 0;

 

                              realNumber = score;

 

                              setInterval(updateDisplayedScore, 10);

                              var displayedNumber:Number = 0;

 

                              function updateDisplayedScore():void

                              {

                              displayedNumber += Math.round((realNumber-displayedNumber)/5);

                              if (realNumber - displayedNumber < 5 && realNumber - displayedNumber > -5)

                              {

                              displayedNumber = realNumber;

                              }

                              addZeros();

                              }

 

                              function addZeros():void

                              {

                              var str:String = displayedNumber.toString();

                              MovieClip(root).scoreTxt.text = str; <------ i use MovieClip(root) as i saw from internet..its working fine.. but

                              }

                    }

but then if for example .. the user died or he reaches the required score.. im suppose to go a certain frame using this code..

MovieClip(this.root).gotoAndStop("Main");

its reaching the frame "Main" but its pointing errors to this --> MovieClip(root).scoreTxt.text

that "Main" frame is on frame 4.. which i did not yet added the TryClass.. should i add to all my frames the TryClass? and how is that?

Sorry for the question.. i dont know yet how to perfectly code in the class.. and accessing the timelines and other external class.. Please dont use deeper language of actionscript.. on a beginner way only..

This topic has been closed for replies.

1 reply

Ned Murphy
Legend
October 11, 2013

The first thing you should do is unnest those two functions and give them their own space in the class.  If you are not familiar with the term, that means do not put functions inside other functions.

If you are getting an error, you should include the full error message.

Participating Frequently
October 11, 2013

okay Sir. I'll try first the first thing that you've said..