开发者

can not access MovieClip properties in flashDevelop

I know there is something I am doing wrong. In my controls I have keydown events that control my hero. As of right now, I am trying to rotate my hero but he refuses to turn . Below is my Hero Class, my control class, and gameobject class. pretty much all the classes associate with the controls class.

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() 
        {

        }

    }

}

Here is my Controls class. This is the class where I am trying to rotate my hero but he doesnt. The keydown event does work cause I trace it.

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

    }

}

Here is GameObject Class

package com.Objects 
{
    import com.Objects.Engine;
    import com.Objects.IGameObject;
    import开发者_如何学C 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
        }

    }

}


Looks like your keyUpListener and keyDownListener methods aren't calling the UpdateObject function.


Try listening for your KeyboardEvent on stage instead of engine.sr (not sure what that is)

If you put them on anything other than the stage you will need to click that specific thing first to give it focus for the events to work.

Also, the line:

 ship.rotation += 3,trace(ship.rotation );

in your Control class looks a bit broken.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜