John L.
John L.

Reputation: 2131

Flash as3 Error 1180 that I don't understand

So, I got an error 1180 message with the following code:

package objects.moving.dudes {
    import flash.utils.Timer;
    import objects.moving.Moving;
    import misc.MoveTimer;
    public class Dude extends Moving {
        public function Dude() {
            addEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
        }
        public var theMoveTimer;
        public function stageAddHandler(e:Event) {
            addEventListener(KeyboardEvent.KEY_DOWN, keyPressed);
            removeEventListener(Event.ADDED_TO_STAGE, stageAddHandler);
        }
        public function keyPressed(e:KeyboardEvent) {
            theMoveTimer = new MoveTimer(e.keyCode);
        }
    }
}

It said, "call to a possibly undefined method MoveTimer".

Here is the class MoveTimer:

package misc {
    import flash.utils.Timer;
    class MoveTimer {
        private const TIMER_LENGTH = 500;
        public function MoveTimer(myKeyCode:int) {
            keyCode = myKeyCode;
        }
        public var keyCode:int;
        public var timer = new Timer(TIMER_LENGTH);
    }
}

I've looked at several different possible solutions to Error 1180, and none of them were applicable/worked for this one. Does anyone know why I'm getting this error?

EDIT: I made some mistakes while transferring my code to stackoverflow, and I have made changes to make it look more like my actual code.

Upvotes: 0

Views: 2006

Answers (3)

John L.
John L.

Reputation: 2131

Solution! And I feel so stupid, but I needed to add the word public to my MoveTimer class:

package misc {
    import flash.utils.Timer;
    public class MoveTimer { //This is the line where I added the word 'public'. See my question for the incorrect version of this line.
        private const TIMER_LENGTH = 500;
        public function MoveTimer(myKeyCode:int) {
            keyCode = myKeyCode;
        }
        public var keyCode:int;
        public var timer = new Timer(TIMER_LENGTH);
    }
}

Upvotes: 0

moosefetcher
moosefetcher

Reputation: 1901

I think the first line of your Dude class should start with 'package'. That, and the changes Binou suggests, ie: adding the MoveTimer type to your theMoveTimer declaration and importing the MoveTimer class in your Dude class.

Upvotes: 0

Benjamin BOUFFIER
Benjamin BOUFFIER

Reputation: 946



as i see you forgot to type your variable theMoveTimer as MoveTimer and the MoveTimer class isn't imported in your Dude class.
Try to change your declaration for theMoveTimer to:

public var theMoveTimer:MoveTimer;

and add the following line to your imports:

import misc.MoveTimer;

Upvotes: 1

Related Questions