# AS3 Screensaver that starts when no mouse / touch activity

**URL:** <https://forum.kirupa.com/t/as3-screensaver-that-starts-when-no-mouse-touch-activity/332078>\
**Category:** flash\
**Created:** [January 20, 2014, 10:03am UTC](https://forum.kirupa.com/t/as3-screensaver-that-starts-when-no-mouse-touch-activity/332078 "2014-01-20T10:03:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![eamiplanet](https://avatars.discourse-cdn.com/v4/letter/e/c37758/32.png) [@eamiplanet](https://forum.kirupa.com/u/eamiplanet)\
**Post date:** [January 20, 2014, 10:03am UTC](https://forum.kirupa.com/t/as3-screensaver-that-starts-when-no-mouse-touch-activity/332078/1 "2014-01-20T10:03:38Z")

</div>

[COLOR=#000000][FONT=verdana]Hi guys[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]Need your assistance.[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]i try to create interactive advertising but stuck with the codes. [/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]There is a main .swf page with few buttons to call another swf files (located in /swfs) …[/FONT][/COLOR]

[COLOR=#000000][FONT=verdana]The AS3 code as below:[/FONT][/COLOR]

\*var Xpos:Number = 110;  
var Ypos:Number = 180;  
var swf:MovieClip;  
var loader:Loader = new Loader();

var defaultSWF:URLRequest = new URLRequest(“swfs/eyesClosed.swf”);

loader.load(defaultSWF);  
loader.x = Xpos;  
loader.y = Ypos;  
addChild(loader);  
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

// Btns Universal function  
function btnClick(event:MouseEvent):void {

removeChild(loader);  
var newSWFRequest:URLRequest = new URLRequest(“swfs/” + event.target.name + “.swf”);  
loader.load(newSWFRequest);  
loader.x = Xpos;  
loader.y = Ypos;  
addChild(loader);  
}  
// Btn listeners  
eyesClosed.addEventListener(MouseEvent.CLICK, btnClick);  
stingray.addEventListener(MouseEvent.CLICK, btnClick);  
demon.addEventListener(MouseEvent.CLICK, btnClick);  
strongman.addEventListener(MouseEvent.CLICK, btnClick);

AND MY WISH IS… IF NO INTERACTION (TOUCH / MOUSE MOVEMENT) AFTER 2 MINUTES… THE MAIN PAGE WILL RUN THE SCREENSAVER (MOVIECLIP IN MAIN PAGE OR CALL ANOTHER .SWF FILES TO START PLAYING)

How do I do this? What would be the best way… just have the screensaver (movieclip) OR call external .SWF

I found this AS2 Scripts but could integrate.

\*code:  
\*\*\*// initialise time passed already

var timeAccounted = 0;

//track time upto 10 mins

this.onEnterFrame = function () {

// get time elapsed since the start

now = getTimer () - timeAccounted;

if (now \>= 600000) {

// if timer gets to 10 mins (600000ms), start playing your screensaver (for testing purposes decrease this number in line above!)

gotoAndPlay (“yourScene”, “startFrame”);

}

};

this.onMouseMove = function () {

// mouse moved? reset elapsed time

timeAccounted = getTimer ();

};  
Then on your button (or in the timeline for the next scene):  
code:  
yourButton.onRelease = function () {

gotoAndPlay(“mainMovie”, “startFrame”);

}

* * *

Txs in advance guys. your assistance highly appreciated. ![](http://forum.kirupa.com/uploads/kirupa/798/c985a958819d8917.gif)\*\*
