Welcome To VertexTemplates.com Flash MX 2004 Tutorials Area - Double Click |
![]() |
|||
Learn how to use getTimer() to make an event happen when a user double clicks.
2. The next thing to do is to make our box movie clip that will be toggle being hidden and visible when the user double clicks on our button. For this example I made a dark gray box with no line color at 200x135. Now select the box and pressF8 to make it a symbol. Choose movie clip as the behavior type and name it box. Finally give the box an instance name of box_mc. 3. Now all we have to do is add the code to toggle our box movie clip. Put the folling code in frame 1 of your root timeline. //set initial variables click = false;First we are setting our declaring our variable click and setting it equal to false. 4. Next we are going to write the onPress function for our movie clip.
//function for the button press
button_btn.onPress = function() {
//if this is the first click
if (!click) {
timer = getTimer()/1000;
_root.click = true;
}
What we are doing here is saying if our variable click is equal to false then we will user getTimer() to find out how much time in miliseconds has passed since the movie started and divide it by 1000 to give us the number in seconds. Then we set our click variable to true so we can test if there is a double click.
5. Lastly we need to find out if there is a double click and perform some sort of action to show the user that they double clicked something. Add the following code right after the if statement.
else {
timer2 = getTimer()/1000;
//if it is a double click
if ((timer2-timer)<.25) {
//toggle the box mc on and off
if (_root.box_mc._visible==false) {
_root.box_mc._visible = true;
} else {
_root.box_mc._visible = false;
}
} else {
timer = getTimer()/1000;
_root.click = true;
}
}
};
What we are doing here is finding out how much time has passed since the movie opened again and then subtracting how much time had passed when the user first clicked. If that time is less than .25 seconds then we either hide the box or make it visible depending on it's current state. Then we set the click variable back to false so that we can start the function over the next time a user clicks. However, if the time is greater than .25 seconds we reset the variables as if it is the first click.
6. Where to go from here. This double click function is very easy to implement in your movies and can serve many purposes depending on what you are trying to accomplish. I am currently using this function in a program where a user logs in to a site the client sees a list of folders that they have access too. Then the user double clicks the folder to open it like he would in an explorer window. Double clicking doesn't have very many uses online because so many things are just set to single clicks, but this can be useful for toggling our box's visibility like before. If you have any questions be sure to email me or post in the discussion for this tutorial. |
||||
| Home Web Templates Affiliate Program Template Tour Custom Website Design Tutorials Articles Contact Us FAQ's All Rights Reserved © 2005 VertexTemplates.com Read our Terms Of Use and Privacy Policy Flash Templates by Metamorphosis Design |
||||