Skip to main content
ETessier
Participant
November 28, 2015
Question

ActionScript Timer not refreshing

  • November 28, 2015
  • 1 reply
  • 346 views

For my Interactive Authoring III class, I created a matching game.

The problem is the timer. It counts down fine but the numbers are not being "reset" properly and when the numbers are changing it is re-writing over itself.

9 doesn't go away and 8 is printed over it, and then 7 is printed over it and so on.

Here is the code that deals with the timer:

// set up the clock

count = 180;

var gameTimer:Timer = new Timer(1000,count);

gameTimer.addEventListener(TimerEvent.TIMER, updateTime);

gameTimer.addEventListener(TimerEvent.TIMER_COMPLETE, timeExpired)

gameTimer.start();

function updateTime(e:TimerEvent):void {

// your class variable tracking each second,

count--;

gameTimeField = new TextField();

gameTimeField.x = 0;

gameTimeField.y = 200;

gameTimeField.embedFonts = true;

gameTimeField.autoSize = TextFieldAutoSize.LEFT;

gameTimeField.defaultTextFormat = digitalFormat;

addChild(gameTimeField);

gameTimeField.text = String("Time: "+ ((count)-gameTimer.currentCount));

}

function timeExpired(e:TimerEvent):void {

var gameTimer:Timer = e.target as Timer;

gameTimer.removeEventListener(TimerEvent.TIMER, updateTime)

gameTimer.removeEventListener(TimerEvent.TIMER, timeExpired)

MovieClip(root).gotoAndStop("gameoverAshton");

}

}

If you want to look at the actual files, the code is in each .as files for each player for each level. Example: Level1Ashton.as

Line 90

If somebody that is good with Action Script coding could take a look at it, I would really appreciate it.

Edith

This topic has been closed for replies.

1 reply

Inspiring
November 28, 2015

You should use one text field only you don't need to create a new text field each time:

gameTimeField = new TextField();

gameTimeField.x = 0;

gameTimeField.y = 200;

gameTimeField.embedFonts = true;

gameTimeField.autoSize = TextFieldAutoSize.LEFT;

gameTimeField.defaultTextFormat = digitalFormat;

addChild(gameTimeField); // all the previous lines should be out of the timer function.


function updateTime(e:TimerEvent):void {

// your class variable tracking each second,

count--;

gameTimeField.text = String("Time: "+ ((count)-gameTimer.currentCount));

gameTimeField.autoSize = TextFieldAutoSize.LEFT;

}


EDIT