Actionscript 3 在as3中激活类

Actionscript 3 在as3中激活类,actionscript-3,Actionscript 3,嗯 所以我在一个塔楼防御游戏中有一个叫做“炮塔”的类,另一个叫做 “炮塔2”我想要的是,当你按下“1”键并点击舞台时,一个炮塔被放置,当你点击“2”键时,炮塔2被放置,有人能帮我做这个吗?(或者可能会告诉我另一个塔防游戏的教程) 这是另一个叫做“Emptyblock”(我放置炮塔的地方)的类,系统没有发现任何错误,所以 package { //importing required classes for this to work import flash.display.MovieClip;

所以我在一个塔楼防御游戏中有一个叫做“炮塔”的类,另一个叫做 “炮塔2”我想要的是,当你按下“1”键并点击舞台时,一个炮塔被放置,当你点击“2”键时,炮塔2被放置,有人能帮我做这个吗?(或者可能会告诉我另一个塔防游戏的教程)

这是另一个叫做“Emptyblock”(我放置炮塔的地方)的类,系统没有发现任何错误,所以

package {


//importing required classes for this to work
import flash.display.MovieClip;
import flash.events.*;
public class EmptyBlock extends MovieClip {//defining the class as EmptyBlock
    private var _root:MovieClip;//creating a _root variable to access root easily
    private var turretone:uint=49;
    public function EmptyBlock() {//this function will always run once EmptyBlock is called
        this.addEventListener(Event.ADDED, beginClass);//create a function that will run once
        this.addEventListener(Event.ENTER_FRAME, eFrameEvents);//create a enterFrame function
    }
    private function beginClass(e:Event):void {
        _root=MovieClip(root);//setting the _root as the root level

        this.buttonMode=true;//make this act like a button
        this.addEventListener(MouseEvent.MOUSE_OVER, thisMouseOver);//adding function for mouseOver
        this.addEventListener(MouseEvent.MOUSE_OUT, thisMouseOut);//adding function for mouseOut
        this.removeEventListener(KeyboardEvent.KEY_DOWN, turret1);

    }
    private function eFrameEvents(e:Event):void {
        if (_root.gameOver) {//remove this and listeners if game is over
            this.removeEventListener(Event.ENTER_FRAME, eFrameEvents);
            this.removeEventListener(MouseEvent.MOUSE_OVER, thisMouseOver);
            this.removeEventListener(MouseEvent.MOUSE_OUT, thisMouseOut);
            this.removeEventListener(KeyboardEvent.KEY_DOWN, turret1);
            MovieClip(this.parent).removeChild(this);
        }
    }
    private function thisMouseOver(e:MouseEvent):void {
        //changing the background so the user know's it's clickable
        this.graphics.beginFill(0x009900);
        this.graphics.drawRect(0,0,25,25);
        this.graphics.endFill();
    }
    private function thisMouseOut(e:MouseEvent):void {
        //changing the background back
        this.graphics.beginFill(0x333333);
        this.graphics.drawRect(0,0,25,25);
        this.graphics.endFill();
    }
    function turret1(e:KeyboardEvent) {
        if (e.keyCode==turretone) {
            _root.makeTurret(this.x,this.y);//make the turret
            //remove all the listeners so it can't be clicked on again
            this.buttonMode=false;
            this.graphics.beginFill(0x333333);
            this.graphics.drawRect(0,0,25,25);
            this.graphics.endFill();
            this.removeEventListener(MouseEvent.MOUSE_OVER, thisMouseOver);
            this.removeEventListener(MouseEvent.MOUSE_OUT, thisMouseOut);
            this.removeEventListener(KeyboardEvent.KEY_DOWN, turret1);


        }
    }
}

}

创建一个类来管理键盘输入并保存当前可使用的项目。按下某个键后,类将切换到链接到该键的项。您应该考虑将代码拆分为更小的可管理块。
// tools swaps active tool class when pressing keyboard
_tools = new ToolManager(stage); // pass stage to class enabling keyboardEvent
_tools.addTool(turrentType1, 49); // bind class to keyCode
_tools.addTool(turrentType2, 48); // bind class to keyCode

// quick listener for click
_board.addEventListener(MouseEvent.CLICK, onBoardClick);


private function onBoardClick(event : MouseEvent) : void
{
  //create new using something like new _tools.activeTool();
}

我仍然有点困惑1)什么是工具2)什么是板