How do I add multiple items to a hitTestObject?

I have a horizontally scrolling flying game involving a character and diferent types of food moving across the screen from right to left which the character has to collect ("hit"). I have the hitTestObject working for 2 different food movieclips with one item belonging to a healthyList, and the other to a junkList.
The problem is I don't know how to add more items (movieclips) to each of the lists, so that I have for example 6 items in the healthyList and 4 items in the junkList.
Below is the code in my Engine.as file. The red highlighted text is the code that creates the problem. I thought that I just needed to add this line in order to add another item to the "healthyList" of food types, but I obviously have it in the wrong place or have the wrong code completely.
package
    import flash.display.MovieClip;
    import flash.display.Stage;
    import flash.events.Event;
    public class Engine extends MovieClip
        private var numClouds:int = 5;
        private var healthyList:Array = new Array();
        private var junkList:Array = new Array();
        private var myFlying:Flying;
        public function Engine()
            myFlying = new Flying(stage);
            stage.addChild(myFlying);
            myFlying.x = stage.stageWidth / 8;
            myFlying.y = stage.stageHeight / 2;
            for (var i:int = 0; i < numClouds; i++)
                stage.addChildAt(new Cloud(stage), stage.getChildIndex(myFlying));
            addEventListener(Event.ENTER_FRAME, loop, false, 0, true);
        private function loop(e:Event) : void
            if (Math.floor(Math.random() * 90) == 5)
                var healthy:Carrot = new Carrot(stage, myFlying);
                var healthy:Broccoli = new Broccoli(stage, myFlying);
                healthy.addEventListener(Event.REMOVED_FROM_STAGE, removeHealthy, false, 0, true);
                healthyList.push(healthy);
                stage.addChild(healthy);
                var junk:Hotdog = new Hotdog(stage, myFlying);
                junk.addEventListener(Event.REMOVED_FROM_STAGE, removeJunk, false, 0, true);
                junkList.push(junk);
                stage.addChild(junk);
        private function removeHealthy(e:Event)
            healthyList.splice(healthyList.indexOf(e.currentTarget), 1);
        private function removeJunk(e:Event)
            junkList.splice(junkList.indexOf(e.currentTarget), 1);
All help and advice very much appreciated.
Thank you!

It's good that you don't expect me to do the work for you - saves me from letting you know that.  Doing the work is how you learn.  I am also not here to teach you, and it looks like you might need to get some basics under your belt before you can pursue something like what you are doing now.
As I already said, the Math.random() method will be one of the key techniques you will need to use for anything you want to have happen randomly.
Usually it comes in handy with randomly choosing an array's index, where the array stores the different items you want to randomly choose.  In your case, the array could store the names of the different functions you could call for each food item you want to add. Or you could have the classes of the objects in the array and randomly choose which one to load in...
   var foodClasses:Array = new Array("Carrots", "Broccoli", "Hotdog", etc...);
this approach requires knowing how to dynamically create a new class instance using only a String value.... for example:
    var ClassRef:Class = Class(getDefinitionByName("className"));
    var classInstance:* = new ClassRef();
    addChild(classInstance);
In that bit of code, the className would be whatever class name you randomly pulled from the array of the class names...
I didn't say it isn't effective, though it can easily fail being effective as well when your file starts getting bogged down with everything else that is going on.  I said it isn't efficient.  It is constantly fliipping a 120-sided coin, as fast as the file's frame rate to see if it comes up 50 or not.  You could use a setTimeout function or a Timer and get much more efficent performance instead... only processing the code when the time passes. 
If you cannot understand how that one line of code works, you are probably in over your head and you need to back up to more basic learning before you can tackle something like what you seem to want to create here. 

Similar Messages

  • How can add multiple item in form .

    hi,
    i have a critical problem .i am creating a check in form for hotel .Now problem is when i fill personal details of Customer with his three family member .here i want to enter all three member name and there relationship with customer .so how can i insert three text fild for name and relation ship in middle of form .Member may be three or Five .
    how can i add multiple item in middle of form according to required .
    Thanks
    Manoj

    I'm assuming that you're talking about an Application Express Form here. In that case, have you thought about using a "master-detail" form? Take a look at the example here Adding a Master Detail Form.
    C.

  • How do I delete multiple items at once instead of one at a time?

    How do I delete multiple items at once instead of one at a time? I have several duplicate items in my library and would like to delete the duplicates. Thanks!

    You can select multiple items using shift to select a range and control to add or remove items from it.
    Regarding duplciates, Apple's official advice is here... HT2905 - How to find and remove duplicate items in your iTunes library. It is a manual process and the article fails to explain some of the potential pitfalls.
    Use Shift > View > Show Exact Duplicate Items to display duplicates as this is normally a more useful selection. You need to manually select all but one of each group of identical tracks to remove. Sorting the list by Date Added may make it easier to select the appropriate tracks, however this works best when performed immediately after the dupes have been created.  If you have multiple entries in iTunes connected to the same file on the hard drive then don't send to the recycle bin. This can happen, for example, if you start iTunes with a disconnected external drive, then connect it, reimport from your media folder, then restart iTunes.
    Use my DeDuper script if you're not sure, don't want to do it by hand, or want to preserve ratings, play counts and playlist membership. See this thread for background. Please take note of the warning to backup your library before deduping, whether you do so by hand or using my script, in case something goes wrong.
    (If you don't see the menu bar press ALT to show it temporarily or CTRL+B to keep it displayed)
    tt2

  • How can I scan multiple items using my HP photosmart 2610 and them be able to be in one attachment​?

    I have an HP photosmart 2610 4 in1. How can I scan multiple items and put them in the same attachment using e-mail? Using my laptop.

    Hi @needyrhelp,
    Welcome to the HP Forums!
    I see that you are wondering how to scan multiple items using your HP photosmart 2610 and for them to be able to be in one attachment in your e-mail. I am happy to look into this for you!
    Please see the how to scan guide for the Operating System you are using. Here is the list of how to scan guides, Scan. Select your Operating System from the list, then select How to scan with HP software, then How to scan a multi-page original text document into a single file. You will need to scan each page one at a time, and add it to the same document. The how to scan guide will show you how. After done scanning to the file, then see the link for How to attach a scan to an email.
    If you do not know the Operating System you are using, please visit this website. Whatsmyos.
    Hope this information is helpful, and thank you for posting!
    RnRMusicMan
    I work on behalf of HP
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to say “Thanks” for helping!

  • How do I add multiple apple id's to one account

    How do I add multiple Apple id's to one account for billing and Icloud use?

    You don't. You can't combine Apple IDs.

  • How do I add multiple contacts to a group?

    How do I add multiple contacts to a group on my Ipad?

    See if this thread helps.
    https://discussions.apple.com/thread/4114588
    Matt

  • How do i add multiple email addresses to my calendar

    How do I add multiple email addresses to my calendar on my iphone

    You can create an email alias at the mail feature at iCloud.com

  • HT201317 how can I add multiple photos to camera roll

    how can I add multiple photos to camera roll

    If you mean from photo stream, open your photo stream album on your phone in the thumbnail view, tap Edit, tap all the photos to select them, tap Share, then tap Save to Camera Roll.

  • How do I add multiple apple ids to my computer iTunes

    How do I add multiple apple ids to my computer iTunes account

    You can authorize more than one account.
    iTunes Store: Authorize or deauthorize your Mac or PC

  • How do i add multiple hp 8600 printers to one account

    how do i add multiple hp 8600 printers to one account

    Hi rexdalehub,
    If you are referring to the ePrint Center, you can simply choose "Add a printer" to the right of your current printers tab.
    I was an HP employee.
    Reminder: Please select the "Accept as Solution" button on the post that best answers your question. Also, you may select the "Kudos" button on any helpful post to give that person a quick thanks.

  • How do you add multiple iTunes to Keynote

    How do you add multiple songs from the iTunes to your Keynote presentation?

    Jer&Renee,
    welcome to Apple Discussions.
    It depends where you want them in your presentation.
    Open the Media inspector and choose a playlist. In the list of entries, mark those you want to add to Keynote (use command-click to mark multiple titles not in one block).
    Then drag the marked titles either on a slide or on the small Audio field (looks like a frame) in Document inspector. When you then hover the cursor at the Audio "frame", you'll see the quick info "Multiple Files". You cannot change the order or remove one of the files, but only all of them.

  • How do I add multiple addresses/contacts in an email tread to my contact list without having to enter each at a time?

    How do I add multiple addresses/contacts in an email tread to my contact list without having to enter each at a time? I have AppleScript but don't see "add address" in any of the boxes/drop-downs. 

    Sorry, but Address Book does not allow you to select more than one email address to send to in a group. There's really no reason why people need multiple copies of a message, anyway; they have the option of forwarding email to another email address of theirs.
    Mulder

  • How do I add multiple iPads to my Apple ID

    How do I add multiple ipads to my Apple ID

    Should just plug it into iTunes and go. You'll just likely need to give each one a different name. That's what i did when I added my iPad to my iTouch on iTunes.
    When you plug them into the computer, give each  a different name and choose to either make them clones of each other (back up XXXX profile onto this iPad) or set each up as a new iPad.

  • HT1040 How do I add multiple different pictures to my order?

    How do I add multiple pictures to my order? It wants me to check out after each one!

    With the amount of information you've provided it's impossible to offer a potential solution.  We can't see your computer so we need to know the details of your problem and setup, i.e.:
    what version of iPhoto are you using?
    what system version are you running?
    can you post a screenshot of the order window?
    OT

  • How can I add multiple email addresses to Address Book?

    How can I add multiple email addresses to Address Book?
    Can it be done from an .xlsx file?

    I have tried that, but the system reads the emails as one long email and I can't find any way of separating them - it ignores spaces, colons and I have also tried putting them through a word doc... still does not work. It works perfectly easily on a PC system!! ( I have just moved to a mac!)
    any ideas would be good
    thanks

Maybe you are looking for

  • Resource injection in DAO?

    I use a Data Acces Object pattern in a Java EE 5 Web-Tier Application. The servlets (and JSP) in the front-end call a separate object that that hides the implementation of accessing data in the databases and maintains the connection to databases. Can

  • How to I cancel a mid stream Itunes purchase?

    I mistakenly started the download process for a audio book when I really wanted to purchase a book through IBooks.The audio book was stopped mid stream.  how do I delete the audio book.

  • Oracle XML vaidation causes database connection lost.

    Schema document: <?xml version="1.0" encoding="UTF-8"?> <xsd:schema xmlns:s="http://www.w3.org/2001/XMLSchema" xmlns:xsd="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" attributeFormDefault="unqualified">      <xsd:annotation>      

  • OGG-01038  Cannot fetch required data from table

    hello i have the following error OGG-01038 Cannot fetch required data from table SIEBEL.S_EVT_MAIL due to missing key columns. here is my extract policy EXTRACT ext3 setenv NLS_LANG=AMERICAN_AMERICA.AL32UTF8 USERID ggs_owner, PASSWORD ******* TRANLOG

  • My Lenovo X60 bips for no apparent reason

    My Lenovo X60 bips for no apparten reason, whether the volume is on or off. The bip happens every 45 seconds or so and it comes from the left side of the machine. Does anyone know why this happen? Does anyone know how to turn it off? thanks Sergigon