1. Code
  2. ActionScript

Quick Tip: Detect User Inactivity in a Flash Movie

Read Time:2 minsLanguages:

In this Quick Tip, you'll learn how to detect when the user has been inactive for a determined time. Keep reading to find out how!

Final Result Preview

Let's take a look at the final result we will be working towards:

Step 1: Brief Overview

We'll detect users interaction using Keyboard and Mouse Events, checking for recent activity using a Timer. We'll display a message if the determined time has elapsed without activity.

Step 2: Set Up Your Flash File

Launch Flash and create a new Flash Document.

Set the stage size to 550x250px.

Step 3: Interface

This is the interface we'll be using, a simple background with a message telling the user to wait for five seconds. The following screen will be shown when the five seconds have passed - convert it to MovieClip and mark the Export for ActionScript box. It's named TheScreen.

Of course this is only one of the many things you can do when the inactivity time passes, GrooveShark for example, pauses the music and shows a message asking the user if he wants to continue using the application. It's your call to decide what to do.

Step 4: ActionScript

This is the class that does the work, read the comments in the code to find out about its behavior.

Step 5: Document Class

Remember to add the class name to the Class field in the Publish section of the Properties panel.


This is a useful and easy way to detect user activity. In this example the activity detected is based in the Mouse and Keyboard events, but you can easily add a Microphone or other input event to meet your needs.

I hope you liked this Quick Tip, thanks for reading!

Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.