Search code examples
actionscript-3animate-cc

Flash An Error- 1013: The private attribute may be used only on class property definitions


I'm trying to make a timer countdown, I believe I have all the pieces there its just keeps giving me this error when whenever I test it.

Any idea what's going on?

package 

{
    import flash.display.MovieClip;
    import flash.events.TimerEvent;
    import flash.utils.Timer;

    public class MainTimer extends MovieClip {
        private var currentMin:int;
        private var currentSec:int;

        private var oneSecondTimer:Timer = new Timer (1000,1);
        public var timeHasStopped:Boolean=false;

        public function MainTimer() {
        // constructor code
            trace("the main timer is here");
            currentMin = 2;
            currentSec = 5;

            minBox.text = String(currentMin);

            if(currentSec < 10)
            {
                secBox.text = "0" + String(currentSec);
            }
            else {
                secBox.text = String(currentSec);
            }

            oneSecondTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
            oneSecondTimer.start();

            private function onTimerComplete(event:TimerEvent):void {
                currentSec = currentSec -1;
                if(currentSec <0) 
                    {
                        currentSec =59;
                        currentMin -=1;
                    } //end if
                if(currentMin < 0) {
                        currentMin =0;
                        currentSec =0;
                        timerHasStopped = true;
                }
                else 
                    {
                        oneSecondTimer.start();
                    }
                minBox.text =String(currentMin);
                secBox.text =String(currentSec);

                if(currentSec <10) 
                    {
                        secBox.text = "0" + String(currentSec);
                    }
            }
    } // Ends Function

} // Ends Class

} // Ends Package

Solution

  • A functon must have opening { braces and must be closed with a } before you make another new function. Your } // Ends Function should be placed after the line oneSecondTimer.start(); and from there onwards you can define you other second function function onTimerComplete

    It might help if you indent your code so you can see easily where things begin & end (use TAB key).

    An example of your indented code would be like below (texts removed), see how this structure makes it easier to see braces & therefore spot any missing or extra braces?

    public function MainTimer() 
    {
        // constructor code
    
        .......
    
        if(currentSec < 10)
        {
            .......
        }
        else 
        {
            .......
        }
    
        .......
    
    } //Ends function called MainTimer
    
    private function onTimerComplete(event:TimerEvent):void 
    {
        .......
    
        if(currentSec <0) 
        {
            .......
        } //end if
        if(currentMin < 0) 
        {
            .......
        }
        else 
        {
            .......
        }
    
        .......
    
        if(currentSec <10) 
        {
            .......
        }
    } //Ends function called onTimerComplete