How to detect HOVER/CLICKS in Starling button with LeapMotionAS3 - actionscript-3

I want to click on Starling buttons using the LeapMotion SCREEN_TAP gesture.
This is possible? To click the Starling button and see the regular push/shrink effect on it using this gesture?
If not...what is the best approach to achieve this?
Any help is welcome!
Regards.

I assume you could do this (I have never done it but I think it should work):
Check whether the tap's coordinates are over the button
If they are, swap the button's texture: var up:Texture = btn.upState; //save reference
btn.upState = btn.downState;
After X milliseconds swap them back: btn.upState = up;

Related

How can I add a sound effect to my buttons?

I want to make a sound effect for my buttons, so when the user clicks it, it goes 'ding'. I have a 1.6 second MP3 file I would like to play upon each click.
I have not started using java-script but everywhere I look, I need java-script to run this. I thought it might be able to be set up like background music.
I figure adding an example of my own code would not help here. I think an example of this will do, and I would be able to understand it reasonable clearly.
Thanks in advance!
This is not very hard. Here is a minimal example:
(Enjoy the Free Software Song)
var button = document.querySelector('button'),
audio = null;
button.addEventListener('click', handler, false);
function handler() {
audio = new Audio('https://www.gnu.org/music/FreeSWSong.ogg');
audio.play();
}
<button>Play</button>

AS3 different image when a button is in use

I have an application for kind of like a homemade microsoft paint made completely in AS3, I am not that advanced in actionscript, but I will ask you my question and thank you in advance!
So I have buttons, each button is a drawing tool, and I want the icon for the drawing tool(button) to be something different than when it is up, down, roll, hit. A compleletley different image to appear ontop of the current button so the user knows what tool is in use while they are using it..
What would be the easiest way to do this with AS3, the timeline and use of movie clips?
Thanks!!
You want to define your button as an instance of SimpleButton, then set the images directly. Kind of like this:
var clearBtn:SimpleButton = new SimpleButton();
clearBtn.upState = mc2;
clearBtn.overState = mc2a;
clearBtn.downState = clearBtn.upState;
clearBtn.hitTestState = clearBtn.upState;
Which I took from a similar question / answer posed on the adobe forums.
If you have these buttons as MovieClips - just change their type to Button in the library. Each button has four keyframes 1- default state, 2 rollover, 3 hit and 4 hit area.
That's the easiest solution without coding.

Having issues with event on click

I have a button instance named "instructionButton" and I'm trying to trace "Clicked." to the output when it is clicked as a test but I haven' been successful thus far. Is there something I'm missing?
I'm using code in Flash Pro 6
import flash.events.MouseEvent;
var clickedVar:String = "Clicked.";
var runVar:String = "mice running...";
trace(runVar);
function instructionOpen(event:MouseEvent):void
{
trace(clickedVar);
gotoAndPlay(255);
}
instructionsButton.addEventListener (MouseEvent.CLICK, instructionOpen);
And of course if there's a more simple way to approach this, all knowledge will be helpful.
Check instance name is provided or not in the property window for the button (click the button and go to menu 'Window->Properties' to open property window)
What name is mentioned in the property window for the button, should use the same instance name in action script coding. Ensure the spelling from both script(code) and property window instance name.
I don't really see anything wrong with your button code, but here's how i do mine in AS3, it may help :) Creating a simple function within the event listener, I use stopPropgation to prevent my button from clicking anything that may be below it in the flash file. ( say you have two buttons on top of one another, you'll click both instead of one)
instructionsButton.addEventListener(MouseEvent.CLICK, function(e){
e.stopPropagation();
trace("Clicked.");
gotoAndPlay(255);
});
This is one button, if you need say fifteen, let me know as I have a code sample I'll give you that i use to create a limitless amount of buttons and eventlistners using switch/case which has been a huge help to me :)
The only way this will not work is if you are not reaching this frame.
Try add this code on your first frame and tell me if this helping.

Button that only works once in flash actionscript 3.0

I have this collecting item game which u have to collect enough "stars" in order to acess a button. After I clicked the "star" button, it suppose to disappear and never appear again. However, when using this script, although the button disappear once I clicked it, when I returned to the frame after going to another frame, it appeared again! pls help!
star1.addEventListener(MouseEvent.CLICK,gotstar);
function gotstar(event:MouseEvent){
stars++;
star1.x = -500;
}
Are you coding on the frames themselves? If so every time you enter a frame it will run every piece of contained code, even if it has already ran once. A solution to this would be to use a document class to track the progress of the game.
you need to remove it from the stage if I understand.
try this instead of star1.x = -500;
stage.removeChild(star1);
star1.removeEventListener(MouseEvent.CLICK,gotstar);
star1.parent.removeChild(star1); in the click handler code (gotstar) should help
however posting your .fla file might be useful for better understanding

mouseX/mouseY Actionscript function equivalent in Cocos2D

This might be irritating simple. I am trying to convert some code from actionscript to cocos2d. I am quite new to actionscript and would like to know if there is a cocos2d function for mouseX/mouseY. If not, what would be the equivalent. Can someone please help me.
In Kobold2D (which is based on cocos2d-iphone) you can use the mouseLocation:
CGPoint mousePos = [KKInput sharedInput].mouseLocation;
KKInput captures the mouse location every time it receives an event. If mouse moved events are enabled, mouse location gives the accurate location of the mouse.
The alternative is to use the NSWindow method mouseLocationOutsideOfEventStream.