Creating a mousehold event - cocos2d-x

Eventually I will implement the following using touch technology. For the time being however I am only after the mouse solution. If a player clicks and holds the mouse on a particular part of the screen, or on a particular sprite/ menuitem (an image of a left arrow for e.g.) then the main game sprite (say a car for e.g.)continues moving to the left until the player releases the mouse button. If a player clicks and holds another part of the screen/sprite/menu item (an image of a right arrow) then the car continues moving to the right until the player releases the mouse button. Note that the mouse does not have to move while the button is being held down.

solved via a combination of mousedown, mouseup and scheduleupdate. So i have two arrows on my screen. A left and right arrow. If the player clicks and holds on the left arrow then the car sprite keeps moving to the left across the screen and vice versa for the right arrow moving the car right. The car only stops moving when the player releases the mouse (mouseup) from the respective arrow.

Related

Move mouse out of bounds Actionscript 3

My problem is really simple
I´ve an artifact with a mouse inside. When you use it it simulates moving the mouse cursor indefinitely to the right.
Of course when i run my project at some point the mouse will reach the right side of the movieclip and the Mouse_Move event wont work anymore
I need a way make my actionscript to recongnise mouse movement even if im out of bounds
(It´s a mobile aplication so using full screen wont work)
In other words i need a Mouse-Motion Listener!
Though it is not possible to track mouse movements outside of flash with only ActionScript, you could capture the mouse position with javascript in the browser and pass it to your SWF.
See this blog as an example. http://www.nelsond8.com/?p=515
You cannot track the mouse position or actions when it moves outside of the stage.
You can however track when the mouse actually leaves the stage using Event.MOUSE_LEAVE:
function mouseLeave(e:Event):void
{
trace("Mouse left the stage.");
}
stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave);
From here you can decide what the most appropriate course of action will be for your application - adding some 'pause' functionality is pretty common.
Tip: MouseEvent.MOUSE_MOVE is what you should use to detect when the mouse re-enters the stage.

How to scroll drag&drop-able objects based solely on their current position on the stage at the time the user scrolls

I'm working in Flash with Actionscript 3. I have a class of objects. Let's say the class is called "apple." At runtime, a number of instances of "apple" are generated on the left half of the stage. Every instance of "apple" can be dragged and dropped anywhere on the stage. Both the left and right halves of the stage have other art on them. What I am trying to construct is some mechanism by which the user can scroll up and down on ONLY the right (as in opposed to left) half of the stage, so that both the art on the right half of the stage and all instances of "apple" currently on the right half of the stage move in unison, while the art and instances of "apple" on the left half of the stage remain stationary. Any advice at all on what kinds of solutions I should be looking into would be greatly appreciated.
In short: You can use hitTestObject to test whether or not the currently dragged/dropped apple ended up on the right side of the screen. Create an array and store the instancenames of the apples on the right side. When the right side scrolls, move the apples in the array accordingly. This can be done by tracking y-coordinates.

AS3 Clicking through the hidden Mask area

I am trying to create a Flash Application similar to www.faceinhole.com.
So far I was able to load my photo through Browse functionality.
Display it inside a movie clip.
Mask this movie clip with an oval shape.
Add the transform controls (senocular) to resize and move the image.
The problem:
Whenever I click on the visible part of the Masked Movie Clip, I can successfully drag my photo around. However when I click on the hidden part of the Masked Movie Clip, I cannot drag my photo around.
Question: Is there a way to add mouseEnabled=false to the hidden area of a mask?
Place a invisible (alpha=0) Sprite on top of everything on the stage or visible section, including the picture and mask and have that drag around. Add a callback to it that updates the picture's position underneath the mask based on the drag values. You'll need to reset the invisible sprite so you can keep dragging the picture and also put limits to how far it can be dragged.

Flash Expandable Banner - Detect Mouse Leave

I have created an expandable banner ad in Flash. Everything is great except one thing. How can I detect when the user is no longer hovering over the flash ad? I have tried to ad a "hit area" which can be used to detect MOUSE_OUT. The issue is, there is a video playing, as well as social media buttons which need to be clickable. If I place a hit area over these, they are no longer clickable. If I place the hit area behind the buttons, the MOUSE_OUT event triggers when you hover over the button.
What is the best practice for a scenario such as this? I have also tried detecting MOUSE_LEAVE on the stage object, but this doesn't seem to function correctly once deployed on an HTML page. Thanks for the assistance.
You can try adding an ENTER_FRAME event that constantly checks stage.mouseX and stage.mouseY. These values should report correctly while the mouse is on the Flash content, and will report the last known mouse coordinates when the mouse is no longer on the stage. However, the last known mouse coordinates may not always be the actual width or height of the stage, so you probably want to add some tolerance in there.
For instance, if your (expanded) Flash content width is 500px, in the ENTER_FRAME event you can check if stage.mouseX is less than 10px (mouse moving off to the left) or more than 490px (mouse is moving off to the right) and minimize the Flash content. Repeat for the height, and adjust tolerance values as needed.
This should give you the effect you want. The only downside that I can see is the overhead of the ENTER_FRAME event just to check whether the mouse has left the content, but I don't see any way around that.

MOUSE_OUT outside of a movieclip?

I'm having a little problem here,
I'm new to Actionscript 3, and what I'm trying to do is build a navigation menu.
What I did is I made a movieclip, added two listeners to it, MOUSE_OVER, and MOUSE_OUT,
the MOUSE_OVER tells the menu to play, so it then animates the opening of it,
the problem though, that when I put my mouse on the buttons themselves, the menu thinks that the mouse is out of it,
I understand that the mouse left the menu itself and entered some other object,
I thought of making a new rectangle, and on the mouse out, to check whether the mouse is really out of the menu's regions, it didn't work though,
I'd be glad to know how to do that,
thanks in advance
You should use the MouseEvent.ROLL_OUT event which fires only if you your mouse is out of the clip and all its children whereas MOUSE_OUT only considers the clip itself.