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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T11:10:42+00:00 2026-05-16T11:10:42+00:00

Okay so I have two png files, a circle and a maze. Basically the

  • 0

Okay so I have two png files, a circle and a maze. Basically the maze is a square with some paths carved through it. I want to draw these images, move the circle to the mouse coordinates, and have a text say ‘hit’ when the circle intersects a wall of the maze and ‘miss’ when it doesn’t. Now I want to do these using the bitmapdata.hittest method. The circle is a 32×32 image and the maze is a 256*256 image. I’ve gotten everything set up and everything draws on the screen correctly but I can’t get the actual collision detection part of it to work, that is it always displays ‘miss’ rather than ‘hit’ even when the circle clearly intersects the maze. Here’s what I’ve done:

package 
{
    import flash.display.*;     
    import flash.events.*;
    import flash.geom.*;
    import flash.text.TextField;
    import flash.utils.getTimer;
    import flash.net.URLRequest;
    import flash.ui.Mouse;
    import flash.system.*;
    import Math;
    public class MAIN extends Sprite
    {
        private var TEXT:TextField = new TextField();
        public var LOADER_1:Loader = new Loader();
        public var LOADER_2:Loader = new Loader();
        public var DATA_1:BitmapData;
        public var DATA_2:BitmapData;

        public function MAIN()
        {   
            LOADER_2.load(new URLRequest('TEST.png'));
            LOADER_2.x = 125;       LOADER_2.y = 125;
            DATA_2 = new BitmapData(256,256,true,0);
            DATA_2.draw(LOADER_2);
            addChild(LOADER_2);

            LOADER_1.load(new URLRequest('BALL.png'));
            LOADER_1.x = mouseX;        LOADER_1.y = mouseY;
            DATA_1 = new BitmapData(32,32,true,0);
            DATA_1.draw(LOADER_1);
            addChild(LOADER_1);

            Mouse.hide();
            stage.frameRate = 60;
            addChild(TEXT);
            stage.addEventListener(Event.ENTER_FRAME,STEP);
        }
        public function STEP(event:Event):void
        {
            LOADER_1.x = mouseX;
            LOADER_1.y = mouseY;

            if (DATA_1.hitTest(new Point(LOADER_1.x,LOADER_1.y),255,DATA_2,new Point(LOADER_2.x,LOADER_2.y)))
            {
                TEXT.text = 'hit';
            }
            else
            {
                TEXT.text = 'miss';
            }
        }
    }
}

So can someone tell me what I’m doing wrong here?

  • 1 1 Answer
  • 1 View
  • 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-05-16T11:10:42+00:00Added an answer on May 16, 2026 at 11:10 am

    You have to wait until your images load before drawing them to a BitmapData.

            LOADER_2.load(new URLRequest('TEST.png'));
            LOADER_2.x = 125;       LOADER_2.y = 125;
            DATA_2 = new BitmapData(256,256,true,0);
            DATA_2.draw(LOADER_2);
    

    At this point you are taking a “snapshot” of your loader, but the loader has no content. So, you should ait for the Event.COMPLETE event to fire on each loader, and the draw to the BitmapData object.

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

Sidebar

Related Questions

okay so I have two arrays $array_one([a]=>2,[b]=>1,[c]=>1); $array_two([a]=>1,[b]=>2,[c]=>1); I want to be able to
Okay, I have two different background .jpgs that I want to used as the
Okay. I want to have two threads running. Current code: public void foo() {
Okay i have two models: posts and comments. as you can think comments has
Okay, I have two OperationContracts and MessageContracts, like this: [OperationContract] OperationResult OperationOnSingleItem(Input input) [OperationContract]
Okay I have two classes for two links and two divs with different information.
okay so I have two projects one in which I have done all the
Okay, so here's the issue. I have two apps that need to package up
Okay so I have two tables, a category table and a posts table. I
I have two tables: one table (okay, it's a view), vComputer, lists many computers

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.