Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other Flash – Timer

  • This topic is empty.
Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #43287
    LaurelBrittany
    Participant

    I am trying to get a timer to work for this game. I get an error at line 36: The private attribute may be used only on class property definitions.

    Here is the last part of the hw assignment for you to compare: http://www.lwebdesigns.net/hw1.docx

    This is the code I have for my MainTimer

    package {

    import flash.display.MovieClip;

    import flash.events.TimerEvent;
    import flash.utils.Timer;

    public class MainTimer extends MovieClip {
    // Init vars for class
    private var currentMin:int;
    private var currentSec:int;
    // create a one second timer from Flash’s Timer class
    private var oneSecTimer:Timer = new Timer(1000,1);

    public var timerHasStopped:Boolean = false;

    public function MainTimer() {
    // constructor code
    trace(“Main timer is here”);
    currentMin = 2;
    currentSec = 5;

    minBox.text = String(currentMin);
    if(currentSec < 10){
    secBox.text = “0” + String(currentSec); //concatenate with a leading zero
    }else{
    secBox.text = String(currentSec);
    }//if end
    oneSecTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
    oneSecTimer.start();

    } // ends onTimerComplete

    } //public function maintimer end
    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{
    oneSecTimer.start();
    } //end else

    //update our display
    minBox.text = String(currentMin);
    secBox.text = String(currentSec);
    //Adjust display for seconds less than 10
    if (currentSec < 10){
    secBox.text = “0” + String(currentSec);
    } // end if
    }// end onTimerComplete
    } //public end
    } //package end

    #127677
    LaurelBrittany
    Participant

    I got it working

    package {

    import flash.display.MovieClip;

    import flash.events.TimerEvent;
    import flash.utils.Timer;

    public class MainTimer extends MovieClip {
    // Init vars for class
    private var currentMin:int;
    private var currentSec:int;
    // create a one second timer from Flash’s Timer class
    private var oneSecTimer:Timer = new Timer(1000,1);

    public var timerHasStopped:Boolean = false;

    public function MainTimer() {
    // constructor code
    trace(“Main timer is here”);
    currentMin = 2;
    currentSec = 5;

    minBox.text = String(currentMin);
    if(currentSec < 10){
    secBox.text = “0” + String(currentSec); //concatenate with a leading zero
    }else{
    secBox.text = String(currentSec);
    }//if end
    oneSecTimer.addEventListener(TimerEvent.TIMER_COMPLETE, onTimerComplete);
    oneSecTimer.start();

    } // ends onTimerComplete

    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{
    oneSecTimer.start();
    } //end else

    //update our display
    minBox.text = String(currentMin);
    secBox.text = String(currentSec);
    //Adjust display for seconds less than 10
    if (currentSec < 10){
    secBox.text = “0” + String(currentSec);
    } // end if
    }// end onTimerComplete
    } //public end
    } //package end

Viewing 2 posts - 1 through 2 (of 2 total)
  • The forum ‘Other’ is closed to new topics and replies.