I'm making a game in AS3 and I've been trying to make a score based on the time since the game started, the score would show when the game is over and would basically be the seconds since the game started multiply by 1000. But I'm struggling to see how to do such thing since I've made the timer in a separate class and I'm trying to add the score to the main document class.
Here's what I've tried:
in the main class:
score.affichageScore.text = "votre score: " + chrono.seconds * 1000;
in this, is the timer class where I used a Date class:
package cem {
import flash.display.MovieClip;
import flash.events.*;
public class Chronometre extends MovieClip {
var begin: Date;
public var seconds: uint = 0;
public function Chronometre() {
// constructor code
}
//************************************************Start the chrono*********************************************//
public function start() {
begin= new Date();
this.addEventListener(Event.ENTER_FRAME, _actualize);
}
//************************************************Stop the chrono*********************************************//
public function stop() {
this.removeEventListener(Event.ENTER_FRAME, _actualize);
}
//************************************************Actualize the chrono*********************************************//
private function _actualize(e: Event) {
var msSpent: uint = new Date().getTime() - begin.getTime();
seconds = Math.floor(msSpent/ 1000);
var milliseconds: uint = msSpent- (seconds * 1000);
affichage.text = seconds + ":" + milliseconds;
}
}
}
The obvious problem is how to get the ''seconds'' variable value from the timer class to the ''score'' variable in the main class?
Timer
class. - null