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

ActionScript Timer not refreshing

New Here ,
Nov 27, 2015 Nov 27, 2015

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

TOPICS
ActionScript
285
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
Enthusiast ,
Nov 27, 2015 Nov 27, 2015
LATEST

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

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