I need help with shooting in my flash game for University

Hi there
Ive tried to make my tank in my game shoot, all the code that is there works but when i push space to shoot which is my shooting key it does not shoot I really need help with this and I would appriciate anyone that could help
listed below should be the correct code
//checking if the space bar is pressed and shooting is allowed
if(evt.keyCode == 32 && shootAllow){
    //making it so the user can't shoot for a bit
    shootAllow = false;
    //declaring a variable to be a new Bullet
    var newBullet:Bullet = new Bullet();
    //changing the bullet's coordinates
    newBullet.y = tank_mc.y + tank_mc.width/2 - newBullet.width/2;
    newBullet.x = tank_mc.x;
    //then we add the bullet to stage
    addChild(newBullet);
listed below is my entire code
import flash.display.MovieClip;
    //declare varibles to create mines
//how much time before allowed to shoot again
var cTime:int = 0;
//the time it has to reach in order to be allowed to shoot (in frames)
var cLimit:int = 12;
//whether or not the user is allowed to shoot
var shootAllow:Boolean = true;
var minesInGame:uint;
var mineMaker:Timer;
var cursor:MovieClip;
var index:int=0;
var tankMine_mc:MovieClip;
var antiTankmine_mc:MovieClip;
var maxHP:int = 100;
var currentHP:int = maxHP;
var percentHP:Number = currentHP / maxHP;
function initialiseMine():void
    minesInGame = 15;
    //create a timer fires every second
    mineMaker = new Timer(6000, minesInGame);
    //tell timer to listen for Timer event
    mineMaker.addEventListener(TimerEvent.TIMER, createMine);
    //start the timer
    mineMaker.start();
function createMine(event:TimerEvent):void
//var tankMine_mc:MovieClip;
//create a new instance of tankMine
tankMine_mc = new Mine();
//set the x and y axis
tankMine_mc.y = 513;
tankMine_mc.x = 1080;
// adds mines to stage
addChild(tankMine_mc);
tankMine_mc.addEventListener(Event.ENTER_FRAME, moveHorizontal);
function moveHorizontal(evt:Event):void{
    evt.target.x -= Math.random()*5;
    if (evt.target.x >= stage.stageWidth)
        evt.target.removeEventListener(Event.ENTER_FRAME, moveHorizontal);
        removeChild(DisplayObject(evt.target));
initialiseMine();
    //declare varibles to create mines
var atmInGame:uint;
var atmMaker:Timer;
function initialiseAtm():void
    atmInGame = 15;
    //create a timer fires every second
    atmMaker = new Timer(8000, minesInGame);
    //tell timer to listen for Timer event
    atmMaker.addEventListener(TimerEvent.TIMER, createAtm);
    //start the timer
    atmMaker.start();
function createAtm(event:TimerEvent):void
//var antiTankmine_mc
//create a new instance of tankMine
antiTankmine_mc = new Atm();
//set the x and y axis
antiTankmine_mc.y = 473;
antiTankmine_mc.x = 1080;
// adds mines to stage
addChild(antiTankmine_mc);
antiTankmine_mc.addEventListener(Event.ENTER_FRAME, moveHorizontal);
function moveHorizontal_2(evt:Event):void{
    evt.target.x -= Math.random()*10;
    if (evt.target.x >= stage.stageWidth)
        evt.target.removeEventListener(Event.ENTER_FRAME, moveHorizontal);
        removeChild(DisplayObject(evt.target));
initialiseAtm();
function moveForward():void{
    bg_mc.x -=10;
function moveBackward():void{
    bg_mc.x +=10;
var tank_mc:Tank;
// create a new Tank and put it into the variable
// tank_mc
tank_mc= new Tank;
// set the location ( x and y) of tank_mc
tank_mc.x=0;
tank_mc.y=375;
// show the tank_mc on the stage.
addChild(tank_mc);
stage.addEventListener(KeyboardEvent.KEY_DOWN, onMovementKeys);
//creates the movement
function onMovementKeys(evt:KeyboardEvent):void
    //makes the tank move by 10 pixels right
    if (evt.keyCode==Keyboard.D)
    tank_mc.x+=5;
//makes the tank move by 10 pixels left
if (evt.keyCode==Keyboard.A)
tank_mc.x-=5
//checking if the space bar is pressed and shooting is allowed
if(evt.keyCode == 32 && shootAllow){
    //making it so the user can't shoot for a bit
    shootAllow = false;
    //declaring a variable to be a new Bullet
    var newBullet:Bullet = new Bullet();
    //changing the bullet's coordinates
    newBullet.y = tank_mc.y + tank_mc.width/2 - newBullet.width/2;
    newBullet.x = tank_mc.x;
    //then we add the bullet to stage
    addChild(newBullet);
if (tank_mc.hitTestObject(antiTankmine_mc))
        //tank_mc.gotoAndPlay("hit");
        currentHP -= 10;
        // remove anti tank mine
        removeChild(antiTankmine_mc);
if (tank_mc.hitTestObject(tankMine_mc))
        //tank_mc.gotoAndPlay("hit");
        currentHP -= 10;
        // remove anti tank mine
        removeChild(tankMine_mc);
    //var maxHP:int = 100;
//var currentHP:int = maxHP;
//var percentHP:Number = currentHP / maxHP;
    //Incrementing the cTime
//checking if cTime has reached the limit yet
if(cTime < cLimit){
    cTime ++;
} else {
    //if it has, then allow the user to shoot
    shootAllow = true;
    //and reset cTime
    cTime = 0;
function updateHealthBar():void
    percentHP = currentHP / maxHP;
    healthBar.barColor.scaleX = percentHP;
    if(currentHP <= 0)
        currentHP = 0;
        trace("Game Over");
    updateHealthBar();

USe the trace function to analyze what happens and what fails to happen in the code you showed.  trace the conditional values to see if they are set up to allow a shot when you press the key

Similar Messages

  • Need help with a customized interactive web application for  apparel

    Help!!!!
    Hi I am a web designer at beginners stage with web
    devlopment. I am seeking guidance on how to develop a customized
    interactive web application so that the end user can change color
    and patterns of apparel on vector images such as teamsports
    uniforms and tshirts. Once the design is customized to their liking
    they can save it with all of the spec information in a file to
    there desktop or to a database to send to the manufacturer.
    Also looking for a possible way to use a CMS so I can upload
    templates of the garment easily for the end user to customize
    online. Can this be done and if so how? This is an example the kind
    of application I am looking for:
    http://www.dynamicteamsports.com/elite/placeorder.jsp
    I am in desperate need of some brilliant developer to help
    with this.
    Thanks in advance for anyone who is willing to assist or give
    me guidance,
    Danka
    "Reap what you sew"

    some parts of that are doable using non-advanced skills, but
    will be difficult and unwieldly if there are more than a few
    colors/patterns.
    saving the image to the server is a bit more advanced and
    you're going to need some server-side scripting like php, perl, asp
    etc. in addition to some flash programming ability.

  • Need help with buying graphics card and ram for MSI 865PE NEO 2-V

    Hi,
    I want to buy 1GB of ram for motherboard MSI 865PE NEO 2-V I need help with finding correct parts.
    I also want to buy 512Mb or 1GB graphics card.
    as i said before i need help with finding correct ones so they match motherboard, I would appreciate if any one would post link to cheap and fitting parts.
    I found graphics card allready, i just need to know if it will fit.
    the card is
    NVIDIA GeForce 7600 GS (512 MB) AGP Graphics Card
    Thanks for help.

    here you can see test reports for your mobo:
    http://www.msi.com/product/mb/865PE-Neo2-V.html#?div=TestReport

  • I need help with re installing my apple account for itunes.

    Had problems with my itune account, so I uninstalled and now need help with re-installing the program with the songs I have already purchased.

    Your iTunes account is something at the iTunes Store online.  It is not possible to uninstall it.  Do you mean the iTunes application?  Even if you delete the application and restore it, it should not have deleted your iTunes library (essentially the contents of the iTunes folder in Music) on your computer unless you did a separate steep and specifically deleted that too.  You need to tell us what it was you deleted.

  • Need help with installing Yahoo style flash menu CS5

    I downloaded the Yahoo style menu bar from the the available widgets.  I got the menu bar to show in Dreamweaver, but need help:
    I have trouble understanding how to use the f-source  flash editor to edit the links.
    I don't seem to be able to drop the  f-source.com button from the menu bar.
    The bar  shows up as a tiny bar in IE8, not as I had programmed it in the widget programmer.
    I was instructed to Insert ==> f-source menus ==> Edit menu in Dreamweaver.  Doing this leads to the following message: "Install at least one f-source menu'.  I did install the f-source-UI G file in the Adobe Extension Manager CS5.  What else needs to be installed?  
    My OS is Windows7 and I am working with Dreamweaver CS5.  Please help.
    Thanks,
    Tony Uythoven

    Flash menus (Flash navigation, period) is a terrible thing from a functional standpoint. It looks really nice, but the honeymoon ends there. As far as SEO goes, your entire site, beyond the landing page, is invisible. A search robot will only see an embeded Flash object.
    You have to ask yourself a basic question.
    1. What is the purpose of building a website and putting it online?
    If it's for your own personal enjoyment and nothing more, then a Flash menu may be for you. If it's for a business or band, or a political group or social group, and you want people to be able to find it in Google, Yahoo, Bing, etc. then you want as many indexible links as possible on your landing page so they will show up in related searches like schedules, articles, galleries, etc.

  • Can you help with a misplaying online Flash game?

    I don't know if this question is appropriate for this forum, but here's taking a chance, and I hope you can help.
    A Flash game I play at discovery.com worked fine about a year ago. I stopped playing it for several months, and then went back to it.
    When I went back to it it didn't play fully any more. It gets to a certain level, then hangs at the same spot every time (some screens download but not enough components to play the game).
    I clear my cache every day, so it's not that. I've updated Firefox (twice since the problem started), so it's not that. I've uninstalled and reinstalled the Flash player - same problem happens. I've tried disabling my add ons - no change. I've tried two other browsers, and the game either stops at the same point, or earlier. I've tried allowing the relevant cookies; doesn't seem to make a difference.
    I've tried messing with Adobe's Flash Global Settings, trying them in different configurations (allowing everything, allowing nothing, and every switch in between); no help.
    I fiddle with my security settings sometimes and wonder if I changed some default setting that is blocking something, or some automated security upgrade in the later browser(s) is doing something.
    I don't seem to have any other Flash problems on my computer (videos play fine); the "test" at Adobe.com works. I have the latest version.
    I'm no technie so if you have an idea, thanks for your input.

    Please check if all your plugins are up-to-date. To do this, go to the [http://mozilla.com/plugincheck Mozilla Plugin Check site].
    Once you're there, the site will check if all your plugins have the latest versions.
    If you see plugins in the list that have a yellow ''Update'' button or a red ''Update now'' button, please update these immediately.
    To do so, please click each red or yellow button. Then you should see a site that allows you to download the latest version. Double-click the downloaded file to start the installation and follow the steps mentioned in the installation procedure.

  • Need help with jerky animation in Flash CC

    Hello,
    I'm creating an animation of a planet orbiting the sun and it is stuttering a little bit no matter what I try.  I'm working in Flash CC, the animation is done with a custom ease and only 2 keyframes (one at the slowest point and one at the fastest).  The end result has to be .mp4 so I am exporting as video.  But even the swf is a little jerky.  My frame rate is 29.97.  The animation path is oval in shape (using an oval guide path which the planet follows), the planet is small, maybe 6 mm across,  and the planet's speed varies as it orbits the sun (thus the custom ease).  The number of frames in the animation is 202, that's how long it takes for the planet to complete one rotation.  That anim is then looped in the movie as a graphic.
    thanks in advance for any help you can give.  

    Here would be a similar example, linear versus an ease tossed in. I made an oval similar to yours (633px by 446px) and just used it as a guide:
    Here's some videos showing the movement I get per frame. You can even see Flash Pro (CS6 in this case) exporting some odd frame choices. For example right before the 5 second mark the circle jumps 2 movements and stays in place for an extra frame (easy to see stepping through it using arrows and Quicktime player). It does this consistently even when using "None" for Quicktime compression, or using a codec.
    Here's some video examples (30FPS over 202 frames, 6.7 seconds):
    Linear Movement
    -60 to 60 ease at the opposite side
    (Source MOV (Animation codec @ 85 quality) to verify MP4 is the same)
    I imagine your results are the same. It's just too much movement for to little time to really get it to play back smooth. Double the time and you'll cut that in half and I think you'll be happier. Increasing FPS beyond 30 might not be a good idea as playback will start to become machine dependant at that resolution and it could bog even worse.

  • Need help with 4-5 camera set up for audio/video podcast

    Hey guys. I'm overseeing the podcast/audiobook studio construction for my company's new entertainment venture. It will ultimately be my job to produce the podcasts and audiobooks. The catch is that they also want to film the podcasts as well. I'm trying to find the most affordable set up that makes the editing/conversion process easiest for me on FCPX.
    As you'll see I'm a bit all over the place. The essentials for what I'm looking for is
    1) The right Camcorder
    2) The most efficient way to record, edit and sync audio
    What is the most affordable camcorder to use that works really well with FCPX? I've been hearing rumors that some aren't compatable and require a tedious conversion process. The Kodak Zi8 seems perfect because it shoots in 1080p and has a mic input, but I'm not sure if it works well with FCPX. Now, I don't know if the mic input is necessary. I was thinking the easiest way to automatically sync audio is by plugging the 4 mics into the camera's mic input and record that way. That should sync everything up automatically right? I also watched a tutorial on the multicam editing option in Final Cut and that seems perfect for this project. Do I need a mic input if I use this method? It seems like the syncing is super easy with the built in camera audio and the podcast audio files together.
    I also would like to be able to record directly into the computer but don't know if that's possible. The process of taking 4-5 SD cards and uploading it after each shoot that way seems super tedious. I'm not sure if there is way to do that.
    Another option would be for us to buy a video switcher but all the options seem so expensive. Anybody know of good hardware that'd work? That way I could edit on the go and if we want to make this a live ustream we can do so. I was also thinking about switcher software and using MIDI. Not sure if that is possible either.

    Lets ignore whether you should be doing this, but, if they are requesting that you do it, have at it.
    Although, the simplicity of this is mind boggling, for them not to do it...ah well, you're donating for a non profit, they are probably the cheapest game in town, and lost the sole employee who could scratch their backside...
    Choice one, I dont recommend this one - File > Print booklet, 2 up saddle stitch. Flip back and forth using the Print Settings button at the bottom to orient the page layout and set paper size. Set the printer as Adobe PDF. Keep checking the Preview in the main Print Booklet dialog, I had to set a page range of 39 pages in a 40 page book for this to work last week.
    Choice two - If you have set a 44 page document with bleeds, export to pdf, toggle "Use ducument bleeds", no crops. Place those reulting pdf's in a new 11 x 17, landscape doc, with appropriate bleeds. How you defined the bleeds in the 44 page document dictates how much fiddling you will have to do at the center (fold line) of the new 11 x 17 "imposed" document. (If your 44 page was not set as facing pages, you might have defind inside bleed to zero. If it was not set as a facing pages document, it references top, bottom, left and right bleeds) (The use of pdf for this is not necessary, you could just as easily place pages from the original InDesign file as pdf's) Setting a blue line/guide line at the center would help to crop in bleeding frames.
    All above seems too simple, you are only needing to impose pages 22-23 for these steps btw.
    @Scott Falkner - I knew I was being to wordy.

  • Need help with a decimal align tab script for CS5

    I have a list that consists of 6 tabbed headers in helvetica bold, followed by a list of numbers that should right align under the headers, and these need to be in helvetica regular. The list is currently in arial font. Is it possible to change both the fonts and set the tabs to align right by using a script? If so, is there one 'out there' somewhere? I am desperate, this is for my daughter's basketball team and they need it asap!
    I am working in indesign cs5 and know how to load and run a script.
    Please HELP!
    Thank you
    Heather

    Hi,
    For some reason I can not download any attached documents from the forums, a bug?
    But anyway, send me an e-mail at "mail (curlya) nobrainer.dk" with the example doc, and i will have a look - no promisses :-)
    Thomas B. Nielsen
    http://www.nobrainer.dk

  • HT2305 I need helping with re-installing Apple Software Update for Windows Vista, please. :)

    Hello,  I will get my new Ipad 2 32GB on April, so I will have enjoying with Ipad with bringing up my excitement on Ipad.   I need re-installing Apple Software Update for Windows Vista 32bit, but I did install iTunes, Safari, and Iphone configuration utility that it did not included Apple Software Update software.   Please send me download file of Apple Software Update, immediate.   Thanks
    I do not certain about Ipad configuration utility, would be working with Iphone configuration utility?
    david

    I went into checking with Apple Software Update then I clicked Control Panel  - "Repair"  It was restored to start menu,  thank you much  thumb up to b noir       Big Helping me!  David

  • Need help with developing a small pool game

    Hi,
    I want to develop a small pool game ....Im using the netbeans ide and ....what I have so far is 2 classes ......Pool and GUI
    Basically the main method is in the Pool class.......withing main I created a new GUI object .....which in turn creates a frame.
    I now want to custom code a rectangle and make it a container for the pool table and also colour it......the thing is can I do animations in a frame and by using independant classes rather than using an applet?
    I know this may be innefficient but I want to create a standalone pool game that uses custom objects and classes for the various tasks. I was just wandering if it was possible to do drawings the way i am saying without using an applet? Its just all the tutorials I see .....well all the code seems messy and lumped together in the one place ....and I basically want things such as a independant ball class and perhaps a painter custom interface that colours rectangles.
    Any advice would be appreciated
    David

    Thanks for the advice .....The thing is I understand pretty well what is needed .....and I have programmed small applications that take bookings for a hotel and and a library ....Im am familiar with references, arraylists and the alike and im also reading about the java collections interface ......I have also coded a simplistic program in the past that basically a ball was bouncing of the sides of a container and made a sound when it hit the edge(this used threads i believe). However it has been a while ......and although I am happy with some of the concepts of java........we did not do any java graphics programming at college. In all fairness though I learned the importance of using classes properly and in a way thats why im finding it so difficult to code even basic graphic movement that Im happy with as the tutorials Ive seen have everything lumped in one place(as mentioned) and trying to make them more modular can be difficult. As far as I know from coding some basic applets they are generated on the client side to enable everyone with different platforms to view stuff over the web. I dont want applets as I dont at this time want to distribute any of my meager programs over the web :-)). It is good to know that I can use threads and such independent of the applet class........I know my question may be naive but 100% of the tutorials I saw invoked the applet class in some way and emplied in a way that it was essential.......I thought there would be a way to do it without using applets but was not 100% sure which is why I asked.
    I will just need to try and find one guide now that actually shows me how to do what im asking:-)
    Cheers
    David
    I also have 3 java books.......each of which concentrate on graphics by use of applets ....im going to look them out again as they might contain something useful .....to be honest though they were a bit of a waste of money lol(well 2 of them were)

  • Need help with (Runescape Classic Graphiced) online game

    I am wondering if someone could link the program Jagex used to make Runescape Classic. Or if you have to, a land generator and character, graphics, object program. If you could also explain how to work it into HTML. That would be good too. I want to put this game (will be massively Multiplayer) on my website. Please help soon.
    P.S. Explain how to make it multiplayer.

    I am wondering if someone could link the program Jagex used to make Runescape Classic.Jagex tends to use proprietary in-house tools, so the odds are that the modeller used to make RS Classic isn't available on the web. To be honest, it wouldn't surprise me to learn that the Gowers hand-coded the early models in a hex editor.
    If you're looking for 3D modelling tools which are used by games developers, you could do worse than Blender or Milkshape3D. However, given that you don't seem to know what an applet is or how to do networking, I think you're biting off more than you can fit in your mouth, let alone chew. Start with learning the basics and think about doing a MMORPG in a year or two.

  • Need help with Photoshop Clone Stamp Tool. For Homework Please??!!!

    Hi Everyone.
    I am trying to create a Type self portrait, It was going well for the first bit. until I closed the program and brought it back up.
    Now when I bring it back the word / stamp changed color. and now its all blurry.... help please???

    I am having similar problem.  Can't open any of CS3 programs after trying to download Dreamweaver Trial, which wouldn't work because "couldn't remove DLM extention" error message.  So now I can not run Illustrator, Photoshop, or even Adobe Reader.  These are properly licensed for about a year. I get "License for product has stopped working".  Have 2 pending cases open with Adobe support (one for Dreamweaver trial, one for license problem) since 8/3 with NO ANSWERS - It says answers within 1-3 business days.  Was on phone support hold today for over 3 hours before line went dead with no help.  What is up with adobe support?  Can anyone help?

  • Need help with export, truncate and import partitions for schema

    I need to export a couple partions for our Oracle 10g Data Warehouse, truncate the partions and re-import the data using the exported file. How can I do this?
    In summary here is what I need to do:
    1) Export partition P_SUB_1 of table1
    2) Export partition P_SUB2 of table2
    3) Truncate P_SUB1 partition of table1
    4) Truncate P_SUB2 partition of table2
    5) Rebuild indexes on table1 and table2
    6) Re-import data into each partition from export files.

    If you have enough free space it might be easier to keep these partition in the database and do an exchange.
    That means:
    create table tmp_sub1 as select * from table1 where 1=0;
    create table tmp_sub2 as select * from table2 where 1=0;
    alter table table1 exchange partition sub1 with table tmp_sub1;
    alter table table2 exchange partition sub2 with table tmp_sub2;After that your have the data of your original partitions in the tmp tables and the particular partitions in the partitioned table are empty and ready for the loading process.
    If the loading process fail and you need to restore the partitions just reverse the exchange statements and you are done.

  • Need help with document that turned into alias for Application

    I'm trying to help my dad with a problem, not sure exactly what he did, but he had a page document in a documents folder on his desktop.  He moved it into a *files folder* on his desktop.  Somehow the document seems to have been turned into an alias for for his application folder. When I click on the file name, the document doesn't open, it opens up the Application folder.
    I'm VERY new to Mac. 
    Any help would be appreciated.  Thank you.

    This should answer the question:
    http://support.apple.com/kb/TA26514

Maybe you are looking for

  • Can I, should I upgrade to GB3?

    Okay, iLife 'o6 is available with GB 3. I got my iMac g5 this summer and have been working with GB2. It's unlikely I will be getting an Intel-chip based Mac in the near future. What is the processing of upgrading to GB3? When you upgrade how does tha

  • Lost my iTunes movies on old hard drive crash, now have new iMac...how do i get them back?

    My old pc hard drive died and decided to get a new IMAC...im able to get all my music, shows, etc but how do I get my movies I purchased on Itunes? Thanks

  • Text gets scrambled for a few seconds

    The text on a webpage appears a bit scrambled and compressed for a few seconds every now and then. It's really disturbing when you try to read. It only started happening very recently.

  • Why has the apps in my grey bar at bottom gone?

    Since Down loading the new software, the short cut app's have disappeared, I have power cycled it and even left it turned off for a time and still all the apps that would be on it have disappeared.

  • Not generating instance when no data

    Hi all, We have a webi report which may be blank (i.e. no data). We want to schedule this report to get a acrobat reader file but we don't want that the instance be generated if there is no data. Is there a way to do this with a scheduling option or