getTimer opr setInterval

Hey, I’m trying to write a function that executes a code when no buttons on my site are pressed within a specific time. For example, if no one presses a button after 10 seconds, I want a certain function to run…how do I do this? Thank You…

Create an empty movieclip and attach this to it.


onClipEvent(enterFrame){
	myTimer = Math.round(getTimer()/ 1000);
	if(_root.pressing == false && myTimer > = 10){
		myFunction();
	}else{
		//do whatever!!
	}
}

Then on your buttons put

on(release){
    _root.pressing = true;
    //then add more actions
}

Hope this helps

Kyle

Hey Kyle, thanks for the response. Now. do I create an empty MC like we did in Flash 5, or do I use the _root.createEmptyMovieClip method in MX…thanx…

Perhaps I missed something but, won’t that code fail to work after a user clicks on a button once? Also, the function will continue to execute because it checks for the value constantly. I dont think this is what you want.

What I mean is:

user loads page: All is quiet for x amount of time, code executes

user loads page: user clicks one button: user stares at the screen for half an hour ***** the code will not execute because the value of pressing has changed once.

I’m going 2 play with Flash now; I’ll post my results…

I would try this…

put this code in a frame


function countemup(){
	stoptime=gettimer()+6000; //this means six seconds
	empty.onEnterFrame=check=function(){
		
		if(getTimer()>stoptime){
			
		trace("function will happen");
		stoptime=getTimer()+6000;
	}
}
}
countemup();

of course, you still need the emptyclip, at least for this version.

put this code on all your buttons.


on(release){
	stoptime=gettimer()+6000; //um.. six seconds again
	trace("time reset, wait 6 seconds");
}

of course, change your time interval to anything you want. If you dont want to nag your users by repeating the functions… you could just set a variable that determines how many times you will bug them for being idle :slight_smile:

Hope this makes sense to you. If not, let me know and I’ll be happy to explain.

Did it help?

Unfortunately not Iammontoya. Let me explain what I’ve tried to do to render a more clearer picture what I’m trying to do.

On a frame in the main timeline, for example, I have this code:

ChangeTime=getTimer()+10000;

Now, on my buttons, I have this code:

on (release){
if(MyButton.onPress.onrollOver == false && ChangeTime>=10000){
function goBack();
}

So, what I’m clearly trying to do is, have my goBack function execute if my buttton hasn’t been pressed within ten seconds, or any of my buttons for that matter. I know this is simple, but I’m just missing the switch. I appreciate any and all assistance.

I’ve read a similar tut somewhat helpful about this on flash kit; here’s the link

http://www.flashkit.com/tutorials/Interactivity/Accessin-Thomas_W-780/index.php

Im baffled, because what I wrote will do exactly that.

As soon as you start your movie the counter will start. In this case it will count up to 6 seconds, unless a button is pressed. If a button is pressed, the counter starts over. How is this not what you were looking for?

I will retry it right now…maybe I did something amiss. I’ll post back…but let me ascertain something: where does this part of your code goes : “empty.onEnterFrame=check=function()” ?

Do I put that code on an empty movie clip’s frame, attach it to an empty movie clip with a handler, or that part of the codes goes on the main time line with the code that’s written above it?

Iammontoya, it didn’t werk, and I coded everything the way you said. If you could prove that your code works by sending a fla. (a fla. of this sort should take a mere couple of minutes to make), I would appreciate it. If not, thanks so much for your help anyway.

here’s the code… I think I only added code for the top button (dont remember)

Thanx alot 4 tha fla…I got everything working now after now…

Kidd Flash

good! For a second there I thought I was going crazy!