# Gun shooting

**URL:** https://forum.kirupa.com/t/gun-shooting/265740
**Category:** Uncategorized
**Created:** [July 11, 2008, 7:38pm UTC](https://forum.kirupa.com/t/gun-shooting/265740 "2008-07-11T19:38:30Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sam\_vickery](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_vickery](https://forum.kirupa.com/u/sam_vickery)
#### Post date: [July 11, 2008, 7:38pm UTC](https://forum.kirupa.com/t/gun-shooting/265740/1 "2008-07-11T19:38:30Z")

</div>

I have go a gun that looks like it shoots but no bullets come out of the gun. I dont know how to do this and I am sort of new to flash. Could you please fill in any missing code and anything else you want on the attached file. Any help on this would be gr8. cheers

---

<div class="post-metadata">

### Author: ![bluemagica](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bluemagica](https://forum.kirupa.com/u/bluemagica)
#### Post date: [July 12, 2008, 5:16am UTC](https://forum.kirupa.com/t/gun-shooting/265740/2 "2008-07-12T05:16:41Z")

</div>

Man you are really a beginner! If i were to help you i would be better of making something from scratch than using your example!But i am currently busy with my exams, so i am just gonna give some tips now

1)your bullet depletion code is the silliest i have seen so far…onClipEvent(enterFrame){} executes all the code in the braces every game loop…that is everytime the playhead reads that frame. So if you have multiple statements put them in one enterFrame function only:

```auto

onClipEvent(enterFrame)
{
 if(condition1)
   statement
 else if(condition2)
   statement
...
...
}

```

but a game designer isn’t a spriter, he should be more of a programmer, and as a programmer you should find the shortest and most flexible route available to you. For example, the above scenario can be minimised as:

```auto

onClipEvent(enterFrame)
{
 for(i=50;i>0;i--) //i starts at 50, and as long as it is greater than 50, lower it by 1
  {
   if(ammo==i)
     _root.bullets.gotoAndStop(50-i) //so if, say you have 45 ammo, it will stop at 50-45=5th frame!!
  }
}

```

2)Your main problem is however, that you cant use attachMovie() properly! Your bullet depletion should have been done with attachMovie, and removeMovieClip() and not with a 50 frame animation, since code gives you greater flexibility than animation! Anyway, the same attachMovie is again required to actually fire a bullet, but rather than stating it here, search google for examples on it…you will learn faster!

if you have problems understanding something, feel free to ask me!

---

<div class="post-metadata">

### Author: ![sam\_vickery](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_vickery](https://forum.kirupa.com/u/sam_vickery)
#### Post date: [July 12, 2008, 12:54pm UTC](https://forum.kirupa.com/t/gun-shooting/265740/3 "2008-07-12T12:54:57Z")

</div>

thanks for the help. I did say that i was new to flash 🙂 Could you make me a quick gun that turns and add a bullet so I can understand it better plz (I will start from scratch dont worry)

---

<div class="post-metadata">

### Author: ![bluemagica](https://avatars.discourse-cdn.com/v4/letter/b/a4c791/32.png) [@bluemagica](https://forum.kirupa.com/u/bluemagica)
#### Post date: [July 12, 2008, 1:22pm UTC](https://forum.kirupa.com/t/gun-shooting/265740/4 "2008-07-12T13:22:31Z")

</div>

As i said earlier, i am a bit busy now with my exam, so i cant really help you, but heres a very nice example that, if you can understand, will teach you a lot of things:

[http://www.emanueleferonato.com/2008/03/27/create-a-flash-game-like-bloons-tutorial/](http://www.emanueleferonato.com/2008/03/27/create-a-flash-game-like-bloons-tutorial/)

---

<div class="post-metadata">

### Author: ![sam\_vickery](https://avatars.discourse-cdn.com/v4/letter/s/a88e4f/32.png) [@sam\_vickery](https://forum.kirupa.com/u/sam_vickery)
#### Post date: [July 12, 2008, 8:01pm UTC](https://forum.kirupa.com/t/gun-shooting/265740/5 "2008-07-12T20:01:08Z")

</div>

thank you very much you have been a good help and good luck with ur exams 🙂
