无法访问flashDevelop中的MovieClip属性

时间:2010-02-12 13:44:15

标签: flex flash actionscript-3 actionscript

我知道我做错了。在我的控件中,我有控制我的英雄的keydown事件。截至目前,我正在试图轮换我的英雄,但他拒绝转身。下面是我的Hero Class,我的控件类和gameobject类。几乎所有的类都与控件类相关联。

package com.Objects 
{
    import com.Objects.GameObject;
    /**
     * ...
     * @author Anthony Gordon
     */

     [Embed(source='../../../bin/Assets.swf', symbol='OuterRim')]
    public class Hero extends GameObject
    {

        public function Hero() 
        {

        }

    }

}

这是我的Controls类。这是我试图旋转我的英雄的类,但他没有。 keydown事件确实有效,因为我跟踪它。

package com.Objects 
{
    import com.Objects.Hero;
    import flash.events.*;
    import flash.display.MovieClip;
    /**
     * ...
     * @author Anthony Gordon
     */
    public class Controls extends GameObject
    {
        private var aKeyPress:Array;
        public var ship:Hero;

        public function Controls(ship:Hero) 
        {
            this.ship = ship;
            IsDisplay = false;
            aKeyPress = new Array();
            engine.sr.addEventListener(KeyboardEvent.KEY_DOWN, keyDownListener);
            engine.sr.addEventListener(KeyboardEvent.KEY_UP,keyUpListener);
        }

        private function keyDownListener(e:KeyboardEvent):void {
            //trace("down e.keyCode=" + e.keyCode);         
            aKeyPress[e.keyCode] = true;
            trace(e.keyCode);
        }

        private function keyUpListener(e:KeyboardEvent):void {
            //trace("up e.keyCode=" + e.keyCode);
            aKeyPress[e.keyCode]=false;
        }

        override public function UpdateObject():void
        {
            Update();
        }

        private function Update():void
        {
            if (aKeyPress[37])//Key press left
                ship.rotation += 3,trace(ship.rotation ); ///DOESNT ROtate      
        }//End Controls

    }

}

这是GameObject Class

package com.Objects 
{
    import com.Objects.Engine;
    import com.Objects.IGameObject;
    import flash.display.MovieClip;
    /**
     * ...
     * @author Anthony Gordon
     */
    public class GameObject extends MovieClip implements IGameObject
    {
        private var isdisplay:Boolean = true;
        private var garbage:Boolean;
        public static var engine:Engine;
        public var layer:Number = 0;

        public function GameObject() 
        {

        }

        public function UpdateObject():void
        {

        }
        public function GarbageCollection():void
        {

        }
        public function set Garbage(garb:Boolean):void
        {
            garbage = garb;
        }
        public function get Garbage():Boolean
        {
            return garbage
        }
        public function get IsDisplay():Boolean
        {
            return isdisplay;
        }
        public function set IsDisplay(display:Boolean):void
        {
            isdisplay = display;
        }

        public function set Layer(l:Number):void
        {
            layer = l;
        }
        public function get Layer():Number
        {
            return layer
        }

    }

}

2 个答案:

答案 0 :(得分:0)

您的keyUpListenerkeyDownListener方法似乎没有调用UpdateObject函数。

答案 1 :(得分:0)

尝试在[{1}}而不是KeyboardEvent上倾听您的stage(不确定是什么)

如果你把它们放在舞台以外的任何东西上,你需要先点击那个特定的东西,让它集中注意力才能使事件发挥作用。

另外,该行:

engine.sr
你的 ship.rotation += 3,trace(ship.rotation ); 课程中的

看起来有点破碎。