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 8110765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T01:52:20+00:00 2026-06-06T01:52:20+00:00

Basically what happens is when I shoot a bullet, it creates the bullet. However,

  • 0

Basically what happens is when I shoot a bullet, it creates the bullet. However, if I click again while the bullet it still on screen, it removes the bullet and makes a completely new one. So now only one bullet can be on the screen at a time. How do I fix this?
The bullet in the library has the instance name of ‘bullet’

package
{



public class GameEnter extends MovieClip
{

    public function GameEnter()
    {
        addEventListener(MouseEvent.MOUSE_DOWN, shootBullet);
    }
    public var _bullet1:bullet = new bullet;
    public var angleRadian = Math.atan2(mouseY - 300,mouseX - 300);
    public var angleDegree = angleRadian * 180 / Math.PI;
    public var speed1:int = 10;

    public function shootBullet(evt:MouseEvent)
    {
        _bullet1.x = 300;
        _bullet1.y = 300;
        _bullet1.angleRadian = Math.atan2(mouseY - 300,mouseX -300);
        _bullet1.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
        addChild(_bullet1);
    }
    public function bulletEnterFrame(evt:Event) 
    {
        var _bullet1 = evt.currentTarget;
        _bullet1.x += Math.cos(_bullet1.angleRadian) * speed1;
        _bullet1.y += Math.sin(_bullet1.angleRadian) * speed1;
        _bullet1.rotation = _bullet1.angleRadian*180/Math.PI;
        if (_bullet1.x < 0 || _bullet1.x > 600 || _bullet1.y < 0 || _bullet1.y > 600) 
        {
            removeChild(_bullet1);
            _bullet1.removeEventListener(Event.ENTER_FRAME, bulletEnterFrame);
        }
    }
}
}
  • 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-06-06T01:52:22+00:00Added an answer on June 6, 2026 at 1:52 am

    Well think about it, you store your _bullet1 variable in the class, which is fine, but every time you shoot you use the same variable and just change the x and y position again.

    A better way to do this is to handle the animation for the bullet in the bullet class itself.

    When you shoot, you just create a new bullet and add it to the stage.

    In case you still want to use this way, it should be more like this:

    public function shootBullet(evt:MouseEvent)
    {
        var bullet:bullet = new bullet();
        bullet.x = 300;
        bullet.y = 300;
        bullet.angleRadian = Math.atan2(mouseY - 300,mouseX -300);
        bullet.addEventListener(Event.ENTER_FRAME, bulletEnterFrame);
        addChild(bullet);
    }
    
    public function bulletEnterFrame(evt:Event) 
    {
        var tmpBullet:bullet = evt.currentTarget as bullet;
        tmpBullet.x += Math.cos(_bullet1.angleRadian) * speed1;
        tmpBullet.y += Math.sin(_bullet1.angleRadian) * speed1;
        tmpBullet.rotation = _bullet1.angleRadian*180/Math.PI;
        if (tmpBullet.x < 0 || tmpBullet.x > 600 || tmpBullet.y < 0 || tmpBullet.y > 600) 
        {
            removeChild(tmpBullet);
            tmpBullet.removeEventListener(Event.ENTER_FRAME, bulletEnterFrame);
        }
    }
    

    But the best way would be to go with option 1

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am not sure whether this only happens to me. Basically if I have
Please see the code below. Basically, when the user creates an object of this
Basically the page is coded centered, but what happens is that on load it
Basically, when one types, a keydown event happens. If the key is held for
Basically, I have a Sql Server database whose schema changes. When this happens, I
This is basically what happens: > git rebase -i HEAD~3 Successfully rebased and updated
This happens only on some ICS devices. What my app is doing is basically
Ok, basically, I have an element that I get which happens to be a
I am having trouble with one of my scripts. What basically happens is that
Basically, I'm having this happen: https://i.stack.imgur.com/el5zH.png I can scroll over to farther than I

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.