(Apache Flex) Right Click brings up the ContextMenu, which I have changed the contents of. All works fine except the MOUSE pointer was hidden to use a custom pointer. The problem is my custom pointer does not move while the context menu is active, nor does the system pointer show because it is hidden. How do I detect the Activation and Deactivation of the Context Menu? An event listener would toggle Mouse show/hide to cure the problem, but I cannot find one for Context Menu De/Activation.
Aaron's solution to use Mouse.cursor worked. Closing.
Related
i'm creating a custom button with React.
The appearance based on the press/release of the mouse/keyboard.
Sometimes it cannot be done by css using :active pseudo, so i need the javascript solution.
So i created a state that listen the onMouseDown/Up & onKeyDown/Up.
The problem is, if the user click the button then drag the mouse out of the button then release the mouse,
i miss the onMouseUp event thus causing the activeState locked up forever.
Do you have a solution for the equivalent of the :active & :not(:active) pair in javascript way?
note:
watching event window.addEventListener('mouseup',...) is still not satisfying me. When the mouse click hold & move out from the browser's window, i still missing the mouseup event.
Update: Apparently this is part of the accessibility scheme of Flex Spark Components
Button control Press the Spacebar to activate the Button control. To cancel activating a button, press the Tab key to move the focus off
the Button control before releasing the Spacebar.
I guess it can be turned off through compiler directives: Accessibility best practices
Question: Is there any reason a Spark Button would trap key events, in particular a "spacebar" key event?
Background: I've inherited and am maintaining a large legacy project done in Flex 4.6. I am seeing a weird behavior with a Spark Button. Essentially, once the button has been clicked on (i.e. given focus) a keyEvent (spaceBar) will trigger the click event handler attached to the button.
Weird, right?
The button is defined in MXML (below) within an MX:Module. The module has key event listeners attached to the stage but the event handlers for those do nothing with the button:
this.stage.addEventListener(KeyboardEvent.KEY_DOWN, echoKeyDownHandler);
this.stage.addEventListener(KeyboardEvent.KEY_UP, echoKeyUpHandler);
If I put a trace statement in the button's event handler to check the event type when this weird behavior occurs, the type is reported as a click. I don't see anything in the docs for the Spark Button about capturing key events like this.
<s:Button id="toggleBtn"
label="Editor"
click="toggleBtn_clickHandler(event)"
x="943" y="8"/>
This is quite normal with Flex. You should also be able to navigate through the interactive elements by using the <tab> key. <space> usually acts like a click. You could try to avoid this by either
a) set the focus to another object after pressing the button
or
b) by checking the keyboardPressed property.
Both is a bit hacky imho. I am not sure if it is possible to turn of keyboard navigation completely in Flex.
[edit 1] I am just thinking if it wouldn't help to simply overwrite the default keyboard handler like this:
override protected function keyDownHandler(evt:KeyboardEvent):void {}
this is inherited by UIComponent. and you would need to create an own component extending s:Button. A little drawback...
[edit 2] I wasn't able to stop thinking about that, even I stopped using Flex 2-3 years ago. So I googled a bit and found this stack overflow post:
How to disable default browser navigation with Space in Flex
I have a bordercontainer and several rectangle objects inside.
I can drag the objects inside the container, but when I right-click a rectangle and move the mouse while rmb is pressed, all dragging stops working. I have no idea why.
Right mouse button is reserved for the context menu. You can not change this. You can add to the context menu but you can not take it away. Clicking the right mouse button on your rectangle should bring up that context menu and stop all dragging. As far as I know, working as intended. If I am misunderstanding, please clarify and I will be happy to assist further if I can.
I'm looking at this:
http://www.netmagazine.com/tutorials/create-page-flip-effect-html5-canvas
However, I have one problem with that - I need to be able to click on the pages, even the edges, without triggering the page turn. I want the pages to turn when a button outside of the canvas is pressed. Is this possible using the base they provided, or do I need to go an entirely different direction?
Yes that can be done.
From what i can see, you need a click event that doesnt trigger the page drag. You need to assign a flag for this.
Let Drag = mouse drag/mouse move, down = mouse down, release = mouse release events respectively.
Initialize your flag variable as false. When a drag event is encountered it becomes true. Otherwise it remains false. As long as it is false when the mouse release event occurs it can be treated as a click. Thats the basic principle behind using mousedown and mouseup as a click event.
You will have to use e.srcElement or e.target to give you the element your cursor is currently positioned over inorder to trigger click functions relative to that element.
If you want a more detailed explanation on the page flip technique then check this out. Helped me lot.
In my application I have a frame, with toolbar (the toolbar contains some actions).
I want the toolbar to be visible only when the window is focused.
So, I registered a windowFocusListener on the window.
The problem is-
when the window is not focused and I click on the place where a tool bar action should be- the action is performed.
This happens because the WindowFocusGained is called before the mouse button is released and when the mouse button released it calls the actionPerformed.
Does anybody has any idea for a work around for this problem?
Does anybody know how to determine wether the mouse button is clicked now?
You could add a MouseListener to the window, and check if the toolbar is visible in the mousePressed event. If the toolbar is not visible at the time the mouse is pressed, set a flag on the toolbar (something like "ignoreNextAction").
In the toolbar, check that flag in your actionPerformed event handler.
Reset the toolbar flag in the mouseReleased event on the window, so that the next click will work correctly.
This is assuming the mouseReleased event on the window happens after the actionPerformed on the toolbar (not sure about this). Worst case, you can work with a timer which resets the flag 50ms after the mouse event.
You could now only hide the toolbar when the window loses focus, but also disable all buttons with setEnabled(false), then re-enable on focus gain. Alternatively, synchronize setEnabled(..) with the visibility of the buttons (instead of the window focus).