TypeError 1009 AS3

时间:2014-01-09 14:01:50

标签: actionscript-3

我一遍又一遍地查看了这段代码,但似乎无法找到问题所在的根源。以下是错误消息:

"TypeError: Error #1009: 
at com.senocular.utils::KeyObject/construct()[C:\Users\nti\Desktop\Ship game\com\senocular\utils\KeyObject.as:29]
at com.senocular.utils::KeyObject()[C:\Users\nti\Desktop\Ship game\com\senocular\utils\KetyObject.as:23]
at com.asgamer.basics1::Ship()[C:\Users\nti\Desktop\Ship game\com\asgamer\basics1\Ship.as:24]
at com.asgamer.basics1::Engine()[C:\Users\nti\Desktop\Ship game\com\asgamer\basics1\Engine.as:17]
"

它肯定不在KeyObject类中,因为它已经下载并且没有被更改(之前已经有过),但是无论如何都是代码片段(注意标记所在的位置)行是):

dynamic public class KeyObject extends Proxy {

    private static var stage:Stage;
    private static var keysDown:Object;

    public function KeyObject(stage:Stage) {
        construct(stage); <---------------------------------------------LINE 23
    }

    public function construct(stage:Stage):void {
        KeyObject.stage = stage;
        keysDown = new Object();
        stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPressed); <--- LINE 29
        stage.addEventListener(KeyboardEvent.KEY_UP, keyReleased);
    }

以下是导致错误的代码部分:

  package com.asgamer.basics1
{

    import flash.display.MovieClip;
    import flash.display.Stage;
    import com.senocular.utils.KeyObject;
    import flash.ui.Keyboard;
    import flash.events.Event;

    public class Ship extends MovieClip
    {

        private var stageRef:Stage;
        private var key:KeyObject;
        private var speed:Number = 0.5;
        private var vx:Number = 0;
        private var vy:Number = 0;
        private var friction:Number = 0.93;
        private var maxspeed:Number = 8;

        public function Ship(stageRef:Stage)
        {
            this.stageRef = stageRef;
            key = new KeyObject(stageRef); <----------------------------- LINE 24

            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
        }

这里是引擎类:

    package com.asgamer.basics1
{
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.Event;

    public class Engine extends MovieClip
    {

        private var numStars:int = 80;
        private var enemyList:Array = new Array();
        private var ourShip:Ship;


        public function Engine() : void
        {
            ourShip = new Ship(stage); <------------------------------- LINE 17
            ourShip.x = stage.stageWidth / 2;
            ourShip.y = stage.stageHeight / 2;

            stage.addChild(ourShip);



            for (var i:int = 0; i < numStars; i++)
            {
                stage.addChildAt(new Star(stage), stage.getChildIndex(ourShip));
            }

            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);

如果有人回答,我真的很感激,因为这个项目对我的最终成绩至关重要!

1 个答案:

答案 0 :(得分:2)

当stage属性仍为null时,正在构建Engine类的实例。这意味着Engine类实例尚未添加到显示列表中。

请参阅:http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/display/DisplayObject.html#stage