Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6582101
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T16:14:19+00:00 2026-05-25T16:14:19+00:00

OK, so i have a class called turret in a tower defense game and

  • 0

OK,

so i have a class called “turret” in a tower defense game and another class called
“turret2” what i want is so that when you press the “1” key and click on the stage a turret is placed and when you click the “2” key turret 2 is placed can someone help me with this ?( or maybe point me towards another tutorial for a tower defense game)

this is another class called “Emptyblock” (Place that i put the turrets) the system didnt find any errors so…

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);


        }
    }
}

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T16:14:19+00:00Added an answer on May 25, 2026 at 4:14 pm

    Make a class that manages your keyboard input and holds the current items you can use. Once you press a key the class switches to the item that is linked to that key. You should really consider splitting up your code into smaller manageable blocks.

    // 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();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a container class (called Atom) that I want to store objects of
I have a class called: ComplexNumber and I have a string that I need
I have a class called Trial which has_many results. Now What I want to
I have a class called Flamethrower which naturally has its own ammunition that is
I have a class called Property that I only need to display a few
I have a Ruby class called LibraryItem . I want to associate with every
I have a class called Image and a class that extends it called ImageSheet
I have a class called GraphView that extends UIView that basically draws a small
I have a class called GestorePersonale which holds a list of instances of another
I have a class called PlayerList, in in that class i have an ArrayList

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.