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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:30:25+00:00 2026-05-25T23:30:25+00:00

Suppose we have a stage with two squares, like so: Suppose we’d like the

  • 0

Suppose we have a stage with two squares, like so:
Our example Flash stage

Suppose we’d like the yellow square to be initially hidden, and we’d like that as long as the mouse cursor is inside the bounds of the red square – the yellow square will be visible, and as long as the mouse cursor is out of the bounds of the red square – that the yellow square will be hidden.

The intuitive approach is to write something like this:

inSqr.visible = false;
outSqr.addEventListener (MouseEvent.ROLL_OVER,sqrOver);
outSqr.addEventListener (MouseEvent.ROLL_OUT,sqrOut);

function sqrOver(e:MouseEvent) {
    inSqr.visible = true;
}

function sqrOut (e:MouseEvent) {
    inSqr.visible = false;
}

With this code, however – any time you move the mouse cursor to within the yellow square –
it, apparently, counts as a ROLL_OUT for the RED square –
thus the sqrOut function is triggered – making the yellow square disappear, and once the yellow square is not there – the cursor is suddenly within the bounds of the RED square again – so the sqrOver function
gets called – bringing back the yellow square’s visibility – triggering sqrOut and so on and so forth, thus creating a “flickering” yellow square when the mouse-cursr is over him:
the yellow square disappears and reappears repeatedly over and over again.

A possible “fix” for this is to remove the listener for the red’s roll-out event while the cursor is inside the yellow (if it’s inside the yellow it surely is inside the red as well), and bring it back when it is out, by adding this to the code above:

 inSqr.addEventListener (MouseEvent.ROLL_OVER,insqrOver);
 inSqr.addEventListener (MouseEvent.ROLL_OUT,insqrOut);
 function insqrOver(e:MouseEvent) {
     if (outSqr.hasEventListener (MouseEvent.ROLL_OUT)) {
         outSqr.removeEventListener(MouseEvent.ROLL_OUT,sqrOut);
     }
     inSqr.visible = true;
 }
 function insqrOut(e:MouseEvent) {
     if (!outSqr.hasEventListener (MouseEvent.ROLL_OUT)) {
         outSqr.addEventListener(MouseEvent.ROLL_OUT,sqrOut);
     }
 }

This works.
But it is cumbersome. You have to do it for each any object inside the bounds of the red square – resulting in long code and many event listeners and continuous listener-registration and unregisteration.

A few years ago someone suggested to me this technique:

 outSqr.addEventListener (Event.ENTER_FRAME,hoverCheck);

 function hoverCheck (e:Event) {
     if (e.currentTarget.hitTestPoint(stage.mouseX,stage.mouseY,true)) {
         inSqr.visible = true;
     }
     else {
         inSqr.visible = false;
     }
 }

This is a simple short code that works.
But, if your project doesn’t really need to use the ENTER_FRAME event it creates the unnecessary overhead and cpu-cycles of repeatedly running the hit test.
Also, if the red square covers the entire stage (has the same dimensions as the stage) –
it creates problems (it doesn’t work).

Is anyone aware of a simple elegant way to accomplish this – one that would not involve too cumbersome and long code and that would not have to use a repeated timer that hit-tests over and over again…?

  • 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-05-25T23:30:25+00:00Added an answer on May 25, 2026 at 11:30 pm

    Place the yellow square inside the red square.

    outSqr.addChild(inSqr);
    

    That will solve your problems nicely and simply. Just be sure outSqr is an instance of the Sprite or MovieClip class.

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

Sidebar

Related Questions

Suppose I have two buttons that are ivar outlets. One is called Blue and
Suppose that we have a data frame that looks like set.seed(7302012) county <- rep(letters[1:4],
Suppose we have the following table data: ID parent stage submitted 1 1 1
Suppose we have a Invoice that is saved in a draft state in a
Suppose I have a pure virtual method in the base interface that returns to
Suppose I have a static method of my class that returns an object of
Suppose we have the name written in any none-latin letters - languages, like Arabic,
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose I have two files containing styles, a.css and b.css. I import them into
Suppose you have to build a DB tables that depicts states and their borders

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.