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

  • Home
  • SEARCH
  • 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 7687043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:36:49+00:00 2026-05-31T19:36:49+00:00

as a follow up to another question here: i’ve build a custom contextmenu item

  • 0

as a follow up to another question here:
i’ve build a custom contextmenu item in a flash application and had a problem with it not showing sometimes.
i found out that the issue was that another sprite was lying “on top” of the item with the custom contextmenu.

however, even with the “mouseEnabled” and “mouseChildren” properties set to false for the item “on top” i still cannot get the custom contextmenu to show…
any ideas? thanks!

ps: here is some code to see the problem:

var spr:Sprite=new Sprite();
spr.graphics.beginFill(0xff0000,1);
spr.graphics.drawRect(0,0,100,100);
addChild(spr);

var blocker:Sprite=new Sprite();
blocker.x=50
blocker.y=50
blocker.graphics.beginFill(0x00ff00,1);
blocker.graphics.drawRect(0,0,100,100);
addChild(blocker);
blocker.mouseEnabled=false
blocker.mouseChildren=false

var customContextMenu:ContextMenu = new ContextMenu();
var item:ContextMenuItem = new ContextMenuItem("custom item");
customContextMenu.customItems.push(item);
item.addEventListener(ContextMenuEvent.MENU_ITEM_SELECT, menuItemSelectHandler,false,0,true);
spr.contextMenu = customContextMenu;

function menuItemSelectHandler(cem:ContextMenuEvent) {
    trace("hello context");
};

when the mouse is over the green rect, the custom contextmenuitem is not shown

  • 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-31T19:36:50+00:00Added an answer on May 31, 2026 at 7:36 pm

    The context menu for an object will be displayed only if the user right-clicks directly on that object itself, as far as I know.

    I’ve simplified your problem in this code:

    public class Test extends Sprite
    {
        public function Test()
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.scaleMode = StageScaleMode.NO_SCALE;
    
            var sprite:Sprite = new Sprite();
            addChild(sprite);
    
            sprite.graphics.beginFill(0xFF0000);
            sprite.graphics.drawRect(0, 0, 200, 200);
            sprite.graphics.endFill();
    
            var shape:Shape = new Shape();
            addChild(shape);
    
            shape.graphics.beginFill(0x0000FF, .6);
            shape.graphics.drawRect(100, 100, 200, 200);
            shape.graphics.endFill();
    
            setUpContextMenu(sprite);
        }
    
        private function setUpContextMenu(target:InteractiveObject):void
        {
            var menu:ContextMenu = new ContextMenu();
            target.contextMenu = menu;
    
            var item:ContextMenuItem = new ContextMenuItem("About Us");
            menu.customItems.push(item);
        }
    }
    

    When you right-click on the area where the red and blue squares overlap, you don’t get the custom context menu.

    Here’s a possible solution, where I’ve modified only the setUpContextMenu() function:

        private function setUpContextMenu(target:InteractiveObject):void
        {
            var menu:ContextMenu = new ContextMenu();
            this.contextMenu = menu;
    
            var item:ContextMenuItem = new ContextMenuItem("About Us");
    
            var handler:Function = function (event:ContextMenuEvent):void {
                // Start with empty menu.
                var items:Array = [];
    
                if (event.mouseTarget == target) {
                    // Directly right-clicked on target. Add custom item.
                    items = [item];
    
                } else if (event.mouseTarget is DisplayObjectContainer) {
                    var o:DisplayObjectContainer
                        = DisplayObjectContainer(event.mouseTarget);
                    var pt:Point = o.localToGlobal(new Point(o.mouseX, o.mouseY));
                    var arr:Array = o.getObjectsUnderPoint(pt);
    
                    // One of the mouse target's descendants is our target,
                    // directly under the pointer. Add custom item.
                    if (arr.indexOf(target) != -1)
                        items = [item];
                }
    
                menu.customItems = items;
            };
    
            menu.addEventListener(ContextMenuEvent.MENU_SELECT, handler);
        }
    

    Here I’m assigning the context menu to the application itself. On the "menuSelect" event, I customize it based on whether the mouse pointer is somewhere above the red square.

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

Sidebar

Related Questions

This is a follow up of another question I asked last night. My problem
This is sort of a follow-up to my question here: Asp:Label is not shown
This is a follow up of another question here on SO . I have
I have a follow-up question regarding an issue I previously had on SO here
As a follow-up to another question , I was wondering what would be the
This is a follow up to another question of mine. The solution I found
Another poster asked about preferred syntax for infinite loops . A follow-up question: Why
I recently asked a question (and had it answered) here: jQuery Load JSON I
PHP mysql database I have created a follow on question to this one here
OK, so this is leading on from another question I asked here recently. Basically,

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.