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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T18:32:12+00:00 2026-06-09T18:32:12+00:00

Essentially I am trying to create a game, where the player has to dodge

  • 0

Essentially I am trying to create a game, where the player has to dodge certain items, so far I have a piece of code that randomly adds 3 sharks to the stage.

The idea is that once the player has hit a shark he/she returns to the start location, I have an Action Script file that contains the speed,velocity etc of the shark, the every time the program is run the sharks will appear in a different location.

However, when I attempt to do a collision test of the sharks only one of the sharks respond, I cannot figure out how to make it that all 3 sharks effect the player (square_mc). Any help would be greatly appreciated.

//Pirate game, where you have to avoid particular object and get to the finish line to move onto the final level.

stage.addEventListener(KeyboardEvent.KEY_DOWN, moveMode ); 
function moveMode(e:KeyboardEvent):void {

//movements for the pirate ship, this will allow the ship to move up,down,left and right.

if (e.keyCode == Keyboard.RIGHT) {
    trace("right"); 
square_mc.x = square_mc.x + 25;
} 
else if (e.keyCode == Keyboard.LEFT) {
    trace("left"); 
square_mc.x = square_mc.x - 25;
} 
else if (e.keyCode == Keyboard.UP) {
    trace("up"); 
square_mc.y = square_mc.y - 25;
} 
else if (e.keyCode == Keyboard.DOWN) {
    trace("down");
square_mc.y = square_mc.y + 25;
}
}   

//for.fla
//this program uses a for loop to create my Sharks
//a second for loop displays the property values of the sharks

function DisplayShark():void{
for (var i:Number=0;i<3;i++)
{
    var shark:Shark = new Shark(500);
    addChild(shark);

    shark.name=("shark"+i);
    shark.x=450*Math.random();
    shark.y=350*Math.random();

}
}
DisplayShark();

for(var i=0; i<3;i++){
var currentShark:DisplayObject=getChildByName("shark"+i);

trace(currentShark.name+"has an x position of"+currentShark.x+"and a y position  of"+currentShark.y);
}



//here we will look for colliosion detection between the two move clips.

addEventListener(Event.ENTER_FRAME, checkForCollision);
function checkForCollision(e:Event):void { 

if (square_mc.hitTestObject(currentShark))
{ 
trace("The Square has hit the circle");
    square_mc.x=50
    square_mc.y=50  //these lines of code return the square back to it's     original location
}

}

  • 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-09T18:32:13+00:00Added an answer on June 9, 2026 at 6:32 pm

    Just move your for loop into the ENTER_FRAME:

    addEventListener(Event.ENTER_FRAME, checkForCollision);
    function checkForCollision(e:Event):void { 
    
        for(var i=0; i<3;i++){    
            var currentShark:DisplayObject=getChildByName("shark"+i);
            if (square_mc.hitTestObject(currentShark))
            { 
                trace("The Square has hit the circle");
                square_mc.x=50;
                square_mc.y=50;
            }
        }
    
    }
    

    You can’t just go through the for loop once and set the currentShark variable – you’ll just end up testing against one shark every time you perform the collision test. Rather, every time you want to check collisions you must loop through all the sharks and do the collision testing.

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

Sidebar

Related Questions

I am trying to create, essentially, a 'kiosk' I have an web application that
I am trying to create a Deep Zoom based multiscale image that essentially has
Alright so what I am trying to do is essentially create a program that,
I have the following code: Tag.find_all_by_company_id(4).each.collect{|tag| tag.name }.join(,) (Essentially I'm trying to build a
I am trying to create a file that is essentially an e-mail with headers
I'm trying to create a procedure that will scan through all items in a
Is this possible? Essentially I'm trying to create a div layout that looks like:
I am trying to create a javascript function within my html document that essentially
I am trying to create an SQL statement that will essentially calculate points due
I'm trying to essentially create a drop down menu tied to a field that

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.