Making a simple ticking clock in AS3 with .as files
I'm making a simple clock in AS3 as seen on youtube (Doug Winnie) but I want to put the code into separate .as files. This is what I have so far but I keep getting the error 1046: Type was not found or was not a compile time constant: secondHand. But it's saying that the location of the error is Line 3 of Clock, but secondHand isn't even mentioned here?
package {
import flash.display.MovieClip;
public class Clock extends MovieClip {
import flash.events.TimerEvent;
import flash.utils.Timer;
import flash.events.MouseEvent;
var clockTimer:Timer = new Timer(1000, 60);
public function Clock(e:TimerEvent):void
{
clockTimer.addEventListener(TimerEvent.TIMER_COMPLETE, endTimer);
}
function endTimer(e: TimerEvent): void
{
trace("Finished");
}
}
}
// startButton and stopBtn are instances of GameButton.
package {
import flash.display.MovieClip;
import flash.events.MouseEvent;
public class GameButton extends MovieClip {
public var startButton : GameButton;
public var stopBtn : GameButton;
public function GameButton():void
{
createListener();
startButton.buttonLabel.text = "Start";
stopBtn.buttonLabel.text = "Stop";
}
public function createListener():void{
startButton.addEventListener(MouseEvent.CLICK, startTimer);
stopBtn.addEventListener(MouseEvent.CLICK, stopTimer);
}
function startTimer(e:MouseEvent):void
{
clockTimer.start();
trace ("Timer started.");
startButton.visible = false;
}
function stopTimer(e:MouseEvent):void
{
clockTimer.stop();
trace("Timer stopped.");
startButton.visible = true;
}
}
}
//
package {
import flash.display.MovieClip;
import flash.events.TimerEvent;
public class secondHand extends MovieClip {
public function secondHand(e: TimerEvent):void {
// constructor code
clockTimer.addEventListener(TimerEvent.TIMER, moveHand);
}
public function moveHand(e:TimerEvent):String
{
secondHand.rotation = secondHand.rotation + 6;
trace("timer");
}
}
}
