-
I have posted this before but got no helpfull respons.
Is there code that I can use for a double click action in flash
Because the Instance is dragable so (press) and (release)
has been used already.
???????????? WHAT DO I DO ?????????????????
-
There is no built-in option for a double-click action in Flash. I know some people have tried experiments with movie clips to simulate it, but I've never seen a functional example.
-
Hi,
You could try this:
There is always a period of time between the mouse pressed event and the mouse released event. If during that time the mouse has moved a significant amount, then start dragging the MC, else treat it as a normal click.
Whats a 'significant amount'?
It is hard to click a button without moving the mouse at all, so you will need to tollerate a small amount of movement for a normal click. You could experiment with different levels of tollerance until you find a setting you like.
Sorry, this is a bit of a rushed explanation, but I am pushed for time. If you want to try this idea, but need some more info, then let me know - I could write some demo code if you are interested.
Bangers
-
Advanced Double-click
flashjunkie has written a tutorial on the double-click:
http://64.224.111.148/forum/tutorial...ick/index.html
Richard
-
Boy, am I stoopid! See post below...
[Edited by Stickman on 09-15-2000 at 04:08 AM]
-
Right, I was mulling this over (in the bath!) last night and realised that I'd overcomplicated the whole thing. Below is an ultra-simple solution that works in much the same way as the others, but with less code.
First, create a movie clip and add the following code in its Object Actions:
Code:
onClipEvent (load) {
clicked = 0;
}
Now, inside the clip create your button and add the following code to its actions:
Code:
on (release) {
mydate = new Date();
if (clicked == 0) {
start = mydate.getTime();
clicked = 1;
return;
}
stop = mydate.getTime();
if (stop - start > 300) {
start = mydate.getTime();
} else {
trace ("clicked");
clicked = 0;
}
}
Which is, I think, about as simple as you can get. Any problems, drop me a line.
-
Tutorial and demo file up, <A HREF="http://web.ukonline.co.uk/members/stickman/tutorials/f5doubleclick.html">here</A>.
-
this code will double to detect whether the button has been single clicked or double clicked...
Now the first part is pretty simple, that is making it respond to a double click. All you need to do is find the difference in time between the first click and the second click and if its approximately < 400ms a double click has been made. e.g: create a button myButton then the following code will trace out when you have made a double click
Code:
myButton.onRelease = function() {
var currTime = getTimer();
var diff = currTime-this.lastTime;
if (diff<400) {
trace("doubleclicked");
}
this.lastTime = currTime;
};
Now the tricky part is to determine whether a user intended a single click rather than a double click. Why? Well because in the process of a double click a single click always occurs. So we kind of need to determine whether a single click or double click was intended by the user.
So the solution to this is as follows: After a single click has been made a setInterval is started (which after 401 ms will trace out that a single click has occured).
But here's the trick, if the button is pressed again within that time period before the trace has occured, we clear that interval as then we know the user is double clicking the button. Hope that makes sense
Code:
myButton.onRelease = function() {
currButt = this;
clearInterval(this.nTimer);
var currTime = getTimer();
var diff = currTime-this.lastTime;
this.nTimer = setInterval(timer, 401);
if (diff<400) {
clearInterval(this.nTimer);
trace("doubleclicked");
}
function timer() {
clearInterval(currButt.nTimer);
trace("single clicked");
}
this.lastTime = currTime;
};
Note:
Note there will a half second delay(401 ms to be exact) to determine whether it is a single click as this is the only way of knowing that a double click was not intended..because thats the time (400 ms) we use to determine whether a double click has occured
So in a nutshell:
A user clicks the button.
If he doesnt click it again within 401 ms a single click is registered.
If he clicks it again within <400ms then a double click is registered.