Zoom in Zoom out loop on action script 3 - actionscript-3

I have this code for my effect to zoom in and zoom out in certains buttons
canada.addEventListener(MouseEvent.MOUSE_OVER, canadaover);
function canadaover(event:MouseEvent):void
{
gotoAndPlay("canadaS");
trace("in");
}
canada.addEventListener(MouseEvent.MOUSE_OUT, canadaout);
function canadaout(event:MouseEvent):void
{
gotoAndPlay("canadaF");
trace("out");
}
canada.addEventListener(MouseEvent.CLICK, clickcanada);
function clickcanada(event:MouseEvent):void
{
trace("Mouse clicked");
}
the problem is when u reach certain corner of the button it kinda gets into a loop, any ideas how can i fix this?
here its the link of the swf i'm trying to do:
http://viajescupatitzio.com/america%20map.swf

If your buttons are MovieClips you can add inside a layer with a mask (for example rectangle) on top. Mask width and height should be your mouseover region and give it alpha = 0. It will be invisible, but it will work with MOUSE_OVER and MOUSE_OUT Events.

You should move your buttons into a different hierarchy level than the graphics you are changing - even if the buttons disappear, or are covered with graphics for just a very short moment, both mouseOver and mouseOut events will be fired (the mouse has left and reentered the button) - and that probably causes your "loop".
It is generally a good idea to have animations and graphical objects within nested MovieClips, and place control elements on a higher level of the display list - that way you can make sure the elements don't overlap and/or interfere.

Related

Which implementation of InteractiveObject that is lightweight should I use to keep track of mousefocus in flex?

I have a spark List control that shows a side-list on ListEvent.ITEM_ROLL_OVER event. Basicaly it shows the contents of the item you are hovering. I would be also using ListEvent.ITEM_ROLL_OUT to hide it again but I want the user to be able to click on it (the sidelist) too.
So, i use MouseEvent.ROLL_OUT and check the event.relatedObject's id to see where the cursor went. I added an invisible Rectangle overlaying the sidelist that's a bit larger so it gains focus 1st. But it doesn't.
Googling around, I think that the Spark Rectangle cant gain focus as it doesn't implement InteractiveObject. What should I use?
My logic:
protected function listOUT(event:MouseEvent):void
{
var obj:Object = event.relatedObject;
if (obj.id != "focusRect")
{
sidelist.visible = false;
}
}
My struggle is to keep the side-list visible if the user moves the cursor from the main list to the sidelist.
Any other suggestions outside my approach are also welcome.
Update
(image link)
Red are the invisible Buttons
On roll_over select the item in the mainlist, display the sidelist
based on the selecteditem in the mainlist.
Hide the sidelist when there is no item selected in the main list.
Deselect items inthe mainlist if the sidelist loses focus.
Furthermore mx.core.UIComponent is the lightest component that dispatches focus events.

Can I create an overlay layer to disable all touches, even on menus?

I need to show a popup layer on a scene, creating a semi-transparent background layer that will also prevent touch events propagation. I am using the latest cocos2d-x v. 3.0-alpha-0.
What I want to achieve is a popup layer that fully handles touches (eg. buttons, menu items, scroll views, etc.), laying on a background layer (for design purposes), that covers the current scene. All items in the scene should not respond to touches any more.
Is this achievable using the new EventDispatcher class? I've been able to disable all touches to the main scene, but all instances of MenuItem that live in the scene are still touchable and active.
How can I achieve this? And, also, how can I create a touch listener that prevents all touches to the main scene but not to the popup?
You can disable menu items by setting setDisable property of menuitems to false.
Example
_menuItem->setEnabled(false);
For Layers use setTouchEnabled property
_backGroungLayer->setTouchEnabled(false);
Make sure that popup layer is not child of layer you want to disable.
To disable all items in menus do this
Suppose _menu contain various menuitems.
CCARRAY_FOREACH(_menu->getChildren(), item)
{
item.isEnabled=NO;
}
if you want to disable selected items just give them tags.There is no need to make any list.
I had the same problem and solved it with mm. It was dirty, but it worked:
Create a button using ccui.button.
Set the button size to your screen size.
Add this button as a background to your popup layer.
This will prevent any thing behind it being clicked.
By default, all CCMenu's have a set priority (kCCMenuHandlerPriority = -128) in cocos2d 2.1. So in a class (usually a CCNode descendant) that wants to swallow everything and preempt anything i do like in this dialog sequencer example below :
- (void)onEnter {
backdrop_.visible = self.isBackDropShown;
MPLOG(#"Adding self as a swallower touch delegate, above the rest of the planet.");
[[[CCDirector sharedDirector] touchDispatcher] addTargetedDelegate:self priority:_dialogTouchPriority swallowsTouches:YES];
for (CCMenu *mn in _menus) {
mn.touchPriotity = _dialogTouchPriority -1 ;
}
[super onEnter];
}
where _dialogTouchPriority is kCCMenuHandlerPriority-1 by default. It will be served before everything 'below'. It is a bad hack (cocos2d internals could be changed and break this), i know , but bullet proof. Use carefully, make certain you only ever have one of these in your scene.

XY restrictions for custom mouse cursor in Actionscript3

I have this interactive 5 seconds animated intro for a website. the preloader and one item are animating and i made the second animation follow the mouse cursor but it has to stay within a certain part of the stage to work with the other animation happening on screen.
I have this code on the movie clip
Mouse.hide();
potistiri.addEventListener(Event.ENTER_FRAME, newCursor);
function newCursor(event:Event): void { potistiri.x = mouseX;
potistiri.y = mouseY; }
and i like i said i just want it to stay in the area i want...
i found this code which gives me errors for not putting the staments if and else if correctly or that it needs a rightparen when i input my numbers in...
if(this._x>Stage.width){
this._x=Stage.width;
}else if(this._x<0){
this._x=0; }
but i cant get it to work...
i need it to move between x 208-656 and y 140-336 and when it gets out of that area the object stay there doing its loop and you see the normal mouse cursor moving in the rest of the screen.
thanks a lot in advance...im leaving my it to the experts in here to pls help me ouy!
The logic you're using in your if/else is fine for clamping the movie clip to a specific area, what exactly do your errors say?
In regards to seeing the normal mouse cursor again you could try using the same if/else checks to determine whether the mouse should or should not be hidden ie if the mouse is outside the area and is hidden, call Mouse.show(), else if it is inside the area and shown, call Mouse.hide().

Reset mouse cursor behavior after changing the default value in AS3

`I have a movie clip that I wanted to behave as a button on mouse over and mouse out, so I added a listener to change the cursor to button and arrow in roll over and roll out:
Object(this).my_mc.addEventListener(MouseEvent.ROLL_OVER,overButton);
Object(this).my_mc.addEventListener(MouseEvent.ROLL_OUT,outButton);
function overButton(e:MouseEvent):void {
Mouse.cursor="button";
}
function outButton(e:MouseEvent):void {
Mouse.cursor="arrow";
}
The problem is that after moving the mouse over and out the my_mc and executing this code, the mouse cursor will always be arrow even when rolling over other button symbols. Is like it will only behave according to the last instruction which is the outButton function.
How can I reset the mouse cursor behavior so that it will work normally with selectable text areas and buttons?
Thanks.
You should probably be restoring the Mouse.cursor property to "auto".
Mouse.cursor="auto"
Setting it to MouseCursor="arrow" on roll out means it will always show the arrow.
However, I would recommend removing these event listeners, and setting the buttonMode property of the MovieClip to true.
It's a bit cleaner, and I'm assuming performs better b/c Flash Player manages this without any extra code.

Is it possible to bubble a MouseEvent by z-index instead of hierarchy?

I have two components being absolutely positioned within a container (they are MapSymbols on an ILOG Elixir map, if that helps). Each component is a VBox with an Image and a Label. Images have functionality tied to the Click event; labels do not.
The problem is when 2 items are positioned so that the label of one is above the icon of another in the z-index, so that the label eats any mouseOver and mouseDown events. Bubbling doesn't help since it bubbles from the label to the vbox to the container, never hitting the lower element. I can't set the vbox to mouseChildren="false", since that keeps the image from getting clicked, as well.
Is there anything I can do with this? The positioning and number of components is data-driven, not something I have control over.
EDIT: some clarification. Each distinct component is structured like this:
<VBox>
<Image source="whatever" click="handleClick()"/>
<Label text="{item.label}/>
</VBox>
The problem is when two of these vboxes are placed close together -- the label of one box may be above the image of the other box, blocking you from interacting with the lower one.
(source: imnotpete.com)
In that example the second label blocks the lower icon -- mouse events are only passed when you interact with the lower half of that icon.
Setting the VBox to mouseEnabled="false" and the Label to mouseEnabled="false" mouseChildren="false" doesn't appear to have any effect - the label still blocks the lower image from receiving mouse events.
The z-index is determined by the display tree, with higher-indexed child DisplayObjects shown above their siblings, so this is how it works already.
What you should be doing is putting your label inside your button as a child, but if you just want to run with the hack, you want:
label.mouseEnabled=false;
label.mouseChildren=false;
label.mouseEnabled = false; would make the area behind the label clickable, isn't that what you need ?