Samsung Gear Vr - handle back button clicks - oculus

how can I handle back button single click , long click to pause game , if pressed again destroy game

I think the back button maps to mouse button 1 so you should be able to pick it up with:
Input.GetMouseButtonDown (1);
To detect double clicks or long clicks you would measure the time between each click or how long the button has been pressed, respectively. I have never tried this but it could be something along the lines of setting up a variable to hold the time interval and checking if the second click happens within that time.
-EDIT-
I just found another discussion about this here with some examples which should help, e.g.
if(Input.GetMouseButtonDown(0))
{
_buttonDownPhaseStart = Time.time;
}
if (_doubleClickPhaseStart > -1 && (Time.time - _doubleClickPhaseStart) > 0.2f)
{
Debug.Log ("single click");
_doubleClickPhaseStart = -1;
}
if( Input.GetMouseButtonUp(0) )
{
if(Time.time - _buttonDownPhaseStart > 1.0f)
{
Debug.Log ("long click");
_doubleClickPhaseStart = -1;
}
else
{
if (Time.time - _doubleClickPhaseStart < 0.2f)
{
Debug.Log ("double click");
_doubleClickPhaseStart = -1;
}
else
{
_doubleClickPhaseStart = Time.time;
}
}
}

Related

Making layers invisible with mouse click

Is it possible to make it so that when you click on a button the first time, a specific layer will become invisible... and then once you click on the button a second time, a different layer would become invisible, and so on? If so could I see an example? Thanks!
What I've tried :
/************************* RESET BUTTON **************************/
reset_btn.addEventListener(MouseEvent.CLICK,reset);
function reset(e:Event) : void
{
eraserClip.graphics.clear();
initEraser();
erasableBitmapData.fillRect(erasableBitmapData.rect, 0xFFFFFFFF);
penny.visible = true;
maskee4.visible = true;
card.visible = false;
greencard.visible = true;
}
The idea is, once I hit the reset button once, the layer named card, will disappear. Underneath that a layer will be there, which is titled greencard. Once I hit the reset button a second time I want the greencard to disappear. As you see above, I was just doing (property name).visible = false;. This works for the first card but not any after because they would not appear.
If I understand you correctly, you could try something like this below :
reset_btn.addEventListener(MouseEvent.CLICK, reset);
var clickCount : int = 0; //# start with zero since no clicks yet
card.visible = true;
greencard.visible = true;
function reset(e:Event) : void
{
clickCount += 1; //# adds +1 to current count of clicks
eraserClip.graphics.clear();
initEraser();
erasableBitmapData.fillRect(erasableBitmapData.rect, 0xFFFFFFFF);
penny.visible = maskee4.visible = true; //# if same value (true) you can chain them like this
if ( clickCount == 1) //if now 1 click
{
card.visible = false;
}
if ( clickCount == 2) //if now 2 clicks
{
greencard.visible = false;
}
}

Need an object to become 'unclickable' behind certain objects. As3 Flash Cs4

How can I make a clickable movieclip 'hide' behind another object. Eg.. I have a rabbit movieclip - he is clickable - as he walks behind a tree(MC) he needs to hide behind that tree.
At the moment, if I click on the tree - the mouse click seems to ignore the tree completely and I can still click the unseen rabbit.
var HitCount:Number = 10;
var RabbitG1X:Number = 0;
var RabbitG1Y:Number = 0;
var RabbitG2X:Number = 0;
var RabbitG2Y:Number = 0;
Mouse.hide();
stage.addEventListener(MouseEvent.MOUSE_MOVE, follow);
function follow(evt:MouseEvent)
{
Cursor_mc.x =mouseX;
Cursor_mc.y=mouseY;
}
stage.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void
{
if (Cursor_mc.hitTestObject(RabbitG1_mc))
{
trace ("you fed rabbit1 ");
RabbitG1_mc.x = RabbitG1X + 5000;
RabbitG1H_mc.x = RabbitG1X + 1271.85;
RabbitG1H_mc.y = RabbitG1Y + 184.05;
HitCount = HitCount -1;
Dec_txt.text = "" + HitCount + "";
}
if (Cursor_mc.hitTestObject(RabbitG2_mc))
{
trace ("you fed rabbit2 ");
RabbitG2_mc.x = RabbitG2X + 5000;
RabbitG2H_mc.x = RabbitG2X + 1271.85;
RabbitG2H_mc.y = RabbitG2Y + 184.05;
HitCount = HitCount -1;
Dec_txt.text = "" + HitCount + "";
}
if (HitCount ==0)
{
trace("You fed all the rabbits");
}
}
I tried adding this to the tree mc to see if I could kill the mouse when it moved over tree.
Tree2MC.addEventListener(MouseEvent.CLICK, solid);
function solid(e:MouseEvent):void{
Tree2MC.mouseEnabled = false;
}
However, it isn't ideal. I really need a clickable object to hide if it goes behind another object on the stage. So if he is half hidden and I click on the part of the MC still revealed, it will click.. And it didn't work.
First, there is no need to use the hitTest code to figure out what was clicked. You can use the mouse event's .target property to figure that out - that will also solve your issue of knowing if the tree was clicked or the rabbit.
For example:
function clickHandler(event:MouseEvent):void {
if (event.target == RabbitG1_mc){
//.....do you stuff
if (event.target == RabbitG2_mc){
Now, one thing to point out, is the .target of an event could also be a child object of a rabbit (if your rabbit MC had other objects inside it). So to make sure it's consistent, you can do something like this when you initialize your rabbits:
RabbitG1_mc.mouseChildren = false;
RabbitG2_mc.mouseChildren = false;
Alternatively, you could just add mouse event listeners to the rabbits directly instead of one listener on the stage that will catch everything. This way, if an object (tree) is in front of them (and is mouse enabled), the click event will dispatch on the tree instead of the rabbit and the clickHandler won't run.
RabbitG1_mc.addEventListener(MouseEvent.CLICK, clickHandler);
RabbitG2_mc.addEventListener(MouseEvent.CLICK, clickHandler);
function clickHandler(event:MouseEvent):void {
//event.currentTarget is a reference to what you attached the listener to
switch(event.currrentTarget){
case RabbitG1_mc:
//..do your code
break;
case RabbitG2_mc:
//..do your code
break;
}
}

Hide button after click two times or more on as3

i am new on as3.
i want to ask how to hide button after click two times or more on as3.
the code below i got from code snippets, but the button hide after one click.
BTNhint.addEventListener(MouseEvent.CLICK, fl_ClickToHide);
function fl_ClickToHide(event:MouseEvent):void
{
BTNhint.visible = false;
}
You have just to count the button clicks and then after two clicks you can hide your button :
var click_counter:int = 0;
BTNhint.addEventListener(MouseEvent.CLICK, fl_ClickToHide);
function fl_ClickToHide(event:MouseEvent):void
{
click_counter ++; // you can write it : click_counter = click_counter + 1;
if(click_counter >= 2){ // you can write it : if(click_counter > 1)
BTNhint.visible = false;
}
}
You can use a constant (LIM) to determine how many times your button must be clicked, compare it to a variable (c) that is counting your clicks, and use your MouseEvent's target property to target your button itself when you want it to disappear:
var c:int = 0;
const LIM:int = 2;
BTNhint.addEventListener(MouseEvent.CLICK, hideMe);
function hideMe(event:MouseEvent):void
{
if(++c >= LIM) event.target.visible = false;
}

flash as3 hitdetection function triggering other function

I am trying to code a script in which a movieclip drops a rope and catches fishes that follows it up if it touches it. here is the issue , i am using hitTestObject to detect collision . Ofcourse the problem is that i trigger the function when it touches but as soon as it doesnt touch the function for moving the movie starts so basically the fish goes up for few seconds and then starts moving straight again .
To try and fix that i tried to make a boolean variable which changes to true or false according to hit and accordingly makes the movieclip moves but also doesnt work because as soon as one mc is not touching the other it changes from true to false or 1 to 0 ..tried both (as in with boolean variable and Number variable) . Any help or putting me on the right direction would be highly appreciated . Thank you so much
// fish capture code
this.addEventListener(Event.ENTER_FRAME,handleCollision);
function handleCollision(e:Event):void
{
if (ropeHit.hitTestObject(fishy_1_a))
{
stopFish1();
trace(movefish1);
}
else
{
moveFish1();
}
}
//code enemy fishy
//fish 1 A
function moveFish1()
{
if (fishy_1_a.x < 800)
{
fishy_1_a.x += xSpeed;
}
else if (fishy_1_a.x >= 800)
{
fishy_1_a.x = -100;
}
}
function stopFish1()
{
fishy_1_a.y -= xSpeed;
}
Define some flag, that you can test:
function handleCollision(e:Event):void {
//Check if fishy is caught
if (!fishy_1_a.catched && ropeHit.hitTestObject(fishy_1_a)) {
//Change flag
fishy_1_a.catched = true;
trace("Gotcha!");
}
if (fishy_1_a.catched) {
stopFish1();
}else {
moveFish1();
}
}

Actionscript 3 Timer on click hold

I have a function where I need to click and cube once and the cube will rotate to that side, then when i click and hold for 2 seconds will go to fifth page or when i click with no hold will start the cube rotating.
This is what I have
var numPressed:Number = 0
function side6(event:MouseEvent):void {
numPressed++;
if (numPressed % 2) {
SimpleZSorter.sortClips(container);
TweenLite.to(container, 1, {rotationX:-8,rotationY:193});
addEventListener(Event.ENTER_FRAME, rotateStop);
removeEventListener(Event.ENTER_FRAME, rotateThis);
}else if (NEED SOEMTHING HERE TO DETECT MOSUE HOLD AFTER SECONDS) {
gotoAndStop(5);
}
else{
addEventListener(Event.ENTER_FRAME, rotateThis);
}
}
The idea atm is numpressed calculates if the presses are odd or even, meaning 1 click will stop the cube rotating, 2 will start it again, a third will stop if and so forth, i need this to keep acting like that.
I need something in the second if statement, everything works well apart from getting it to work on holding the mouse.
Any help appreciated
Ian
I would suggest using MouseEvent.DOWN and MouseEvent.UP and store Date.time for this.
EG: This set of functions would track the ammount of millisenconds elapsed between the MouseEvent.DOWN and the MouseEvent.UP event.
private var mouseDownTime:Number = NaN,mouseUpTime:Number = NaN;
private function init():void
{
yourCubeObject.addEventListener(MouseEvent.DOWN,onMouseDown);
yourCubeObject.addEventListener(MouseEvent.UP,onMouseUp);
yourCubeObject.addEventListener(MouseEvent.OUT,onMouseOut);
}
private function onMouseOut(event:MouseEvent):void
{
mouseDownTime = mouseUpTime = NaN;//clear storage
}
private function onMouseDown(event:MouseEvent):void
{
mouseDownTime = new Date().time;//store system time in milliseconds since epoc
}
private function onMouseUp(event:MouseEvent):void
{
mouseUpTime = new Date().time;
if (!isNaN(mouseDownTime))//avoid error case where mouse went down outside object
{
if ((mouseUpTime - mouseDownTime) >= 2000)
{
//mouse held down for more the 2 seconds, your function here.
}
}
onMouseOut(event);//reset counters
}