Flex : Menu doesn't hide automatically? - actionscript-3

I am creating a menu this way :
myMenu = Menu.createMenu( null, myMenuXMLListCollection, false );
and then showing it with :
myMenu.popup( 10, 10 );
but the menu doesn't disappear automatically when i click somewhere outside the menu.
Is there some way to make the menu disappear automatically when i click outside it ?

Listen for the SandBoxMouseEvent.MOUSE_UP_SOMEWHERE on the sandbox root. You can get the Sandbox root using SystemManager.getSandboxRoot
So, add your event listener, something like this:
systemManager.getSandBoxRoot.addEventListener(SandboxMouseEvent.MOUSE_UP_SOMEWHERE, myMouseUpHandler);
And then in your event handler, just check to see if the target is the menu and if not hide the menu:
protected function myMouseUpHandler(event:SandboxMouseEvent):void{
if(event.target != myMenuInstance){
myMenuInstance.visible = false;
// or whatever other action you wish to take to hide the menu.
}
}
This is the general approach that the Flex ComboBox uses to hide the drop down menu on mouse click.

Related

MarkupCore - Is it possible to disable rightClick on a hovered markup in ForgeViewer?

Whenever I hover a markup and right click it, it locks the mouse movement to the drawing and makes it impossible to move the mouse without moving the drawing.
Is it possible to disable this behaviour?
Depending on your specific scenario, there's a few things you can try:
If you're trying to enable camera pan while in the markup mode on a 2D drawing, you can simply "enable navigation" for the markup tool:
viewer.toolController.getTool('markups.core').allowNavigation(true);
If that's not sufficient for your case, you could also try and modify the handleButtonDown method that the markup tool uses to decide whether and how it should handle the mouse button down event. Currently the method looks like this:
this.handleButtonDown = function(event, button) {
if (this.allowNav || (this.is2d && (avp.isRightClick(event, this.viewer.navigation) || avp.isMiddleClick(event)))) {
// If pan tool won't handle button down, then pass over the event
if (this.panTool && this.panTool.handleButtonDown) {
return this.panTool.handleButtonDown(event, button);
} else return false;
}
return true; // Consume event
};
Where avp is just a shortcut to the Autodesk.Viewing.Private namespace.
viewer.toolController.getTool('markups.core').handleButtonDown = function (event, button) {
// Return true when you want the measure tool to "capture" the event and process it somehow,
// or false when you want to ignore the event and allow other tools on the stack to handle it
};

Extjs4: how do I add a listener when I change my panel

How do I add a listener when I change my panel to another panel in same tab?
I know there is a function is tabchange, when my tab is changed and listener is working.
Like this:
tabchange:function(tabPanel, tab){
if(tab.id == "selecttraffic"){
setclickmap = 'line';
map.addControl(clickmap);
clickmap.activate();
} else if(tab.id == "selectrange"){
setclickmap = 'range';
map.addControl(clickmap);
clickmap.activate();
}
}
But I can't find a similar function work to my panel change!!!
Thanks!
You need to describe it more specifically. Event tabchange fires when a new tab has been activated/selected. What do you mean here by change my panel to another panel in same tab?

AS3: What is the best way to put button-behaviors ONLY on child_mcs of a container_mc

I have a container_mc, with lots of child_mcs inside. I want the child_mcs to have full button-like behaviors (click-able, cursor effects).
I am not interested in putting individual mouse listeners on every child.
... I would like to simply have one listener on the parent container, though the parent would effectively be inactive ... only the child_mcs.
Delfine the common behaviour of the buttons in a class and associate that class with the button symbol in the library.
You could listen to click events on the container with the useCapture flag set to true (addEventListener's third argument) - the listener would be invoked every time any container's child (including grandchildren and so on) is clicked. Then you could check which button was clicked for example by examining its name property.
Let's assume you have something like this:
var container_mc:Sprite = new Sprite();
addChild(container_mc);
container_mc.addChild(button1);
container_mc.addChild(button2);
//and so forth with all your buttons
To do what you ask, you would do the following:
//add a click listener to the container
container_mc.addEventListener(MouseEvent.CLICK,click);
//make the buttonMode true on the container, so you get the button hand cursor
container_mc.buttonMode = true;
function click(e:Event):void {
//e.target is a reference to what was clicked (see caveat after code sample)
//if all the children of container_mc are of the same custom class,
//you could now call a click handler on that item
MyButtonClass(e.target).myClickHandler(e);
//or you could use a switch statement
switch(e.target){
case button1:
//button 1 was clicked, do something with it
break;
case button2:
//button 2 was clicked, do something with it
break;
}
}
The only caveat here, is an event's target could be any child down line of container. So if button1 had some children and those children had children, the object referenced in e.target could be any of them (which ever was clicked). If you have child object inside your button, then the easiest way to make sure your target is always the button, is do the following:
button1.mouseChildren = false;
That will ensure any mouse events dispatched by the button, will have button1 as the target and not any of it's children.
please ignore the downvote ... if your problem is the same as mine,
then this solution works
//-- pseudo code --\\
*for the container:*
container.addEventListener( MouseEvent.MOUSE_DOWN , callback_function ) ;
container.buttonMode ...... false
container.mouseEnabled .... false
container.mouseChildren ... true
*for each child:*
child.buttonMode ...... true
child.mouseEnabled .... true
child.mouseChildren ... false

Detect tap in page?

I have a PhoneApplicationPage with some grids, images and a few buttons. If I tap outside my buttons, anywhere in the page (on an image, grid or whatever), I want to open a new page.
How can I detect a tap/click anywhere on the page?
I see at least two ways to do that:
Listen to the MouseLeftButtonUp event on your PhoneApplicationPage. It should be triggered by images and labels but not by buttons
Listen to the Tap event on your PhoneApplicationPage. However, this event will be triggered even when the user tap on a button. To prevent this, you can retrieve the list of controls at the tap coordinates in the event handler, and open the new page only if there's no button:
private void PhoneApplicationPage_Tap(object sender, System.Windows.Input.GestureEventArgs e)
{
var element = (UIElement)sender;
var controls = VisualTreeHelper.FindElementsInHostCoordinates(e.GetPosition(element), element);
if(controls.OfType<Button>().Any())
{
return;
}
// Open the new page
}

how to get a button in an Openlayers popup?

I am trying to put a button inside of an Openlayers popup. While the button appears to display correctly with the following code, the function 'handlerFunc' does not execute when the button is clicked. The segment of code I have posted is all within another function (so handlerFunc is actually a nested function). I'm using JQuery for the button itself. Any ideas on what might be going wrong? Thanks!
var feature = new OpenLayers.Feature(presences, ll);
feature.popupClass = popupClass;
feature.data.popupContentHTML = "<button id='popupButton'>Click me</button>";
feature.data.overflow = (overflow) ? "auto" : "hidden";
feature.data.icon = markerIcon;
$('#popupButton').button();
$('#popupButton').click(handlerFunc);
function handlerFunc() {
// do something
}
Most likely reason is that your button doesn't exist when you bind to a click event. $('#popupButton') returns null. Instead of using $('#popupButton').click(handlerFunc); try $('#popupButton').live('click', handlerFunc);. That means that we bind to an event not only when DOM is built, but when object appears.