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

Making a simple ticking clock in AS3 with .as files

New Here ,
Apr 03, 2014 Apr 03, 2014

Copy link to clipboard

Copied

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");

        }

    }

}

TOPICS
ActionScript

Views

640

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2014 Apr 03, 2014

Copy link to clipboard

Copied

copy and paste the error message.

Votes

Translate

Translate

Report

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
New Here ,
Apr 03, 2014 Apr 03, 2014

Copy link to clipboard

Copied

C:\Users\Claire\Desktop\CLOCK\secondHand.as, Line 81018: Duplicate class definition: secondHand.
C:\Users\Claire\Desktop\CLOCK\Clock.as, Line 15000: The class 'Clock' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
C:\Users\Claire\Desktop\CLOCK\GameButton.as, Line 15000: The class 'GameButton' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.
C:\Users\Claire\Desktop\CLOCK\secondHand.as, Line 15000: The class 'secondHand' must subclass 'flash.display.MovieClip' since it is linked to a library symbol of that type.

Votes

Translate

Translate

Report

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
Community Expert ,
Apr 03, 2014 Apr 03, 2014

Copy link to clipboard

Copied

you're using a secondHand class different from the one you posted here.

Votes

Translate

Translate

Report

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
Guide ,
Apr 04, 2014 Apr 04, 2014

Copy link to clipboard

Copied

LATEST

The problem is that you've named your Class secondHand. Inside it is (apparently) an instance, also named secondHand. The Player has no idea which one you mean. This is one of the reasons for the convention that Class names should be camel case starting with a capital letter and instance names should be camel case starting with a lower case letter. Rename your secondHand Class to SecondHand and the error should go away.

Also note that there doesn't seem to be much point in breaking out the Classes the way you did, because the majority of the logic seems to be in GameButton. GameButton should only dispatch a start and stop event and manage its own state. The Clock should not be inside it.

Votes

Translate

Translate

Report

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