Web Design Forum: Creating custom Events - Web Design Forum

Jump to content

WDF
WDF Premium Memberships Reseller Hosting
Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

Creating custom Events Rate Topic: -----

#1 User is offline   Michael Wilson 

  • Forum Newcomer
  • Pip
  • Group: Members
  • Posts: 10
  • Joined: 12-August 08
  • Reputation: 0
  • Location:Bournemouth
  • Experience:Nothing
  • Area of Expertise:Designer

Posted 08 September 2008 - 02:53 PM

Hi guys,

I'm currently building a flex media player for a client and I am looking to have the controls fade out when the user has been inactive for 3 seconds. I have found an actionscript class that prints a message in a text box after a set period.

However, I need to convert this class into an extension of the effect class. This is where I become stuck.

Can you please help?

The class I currently have is:

package utils{
import flash.events.KeyboardEvent;
import flash.events.MouseEvent;
import flash.utils.clearInterval;
import flash.utils.setInterval;

import mx.core.Application;

public class IdleUserWatcher{
// is the user active?
private var __isActive : Boolean = false;
// the id for the interval
private var intervalID : Number;
// how long to wait before calling is idle... default is 1 second
private var idleTime : Number = 1000;
// a list of all objects listening
private var listeners : Array;
// readonly property for isActive

public function get isActive () : Boolean{
return this.__isActive;
}

public function IdleUserWatcher(idleTime:Number = 1000){
Application.application.addEventListener(MouseEvent.MOUSE_MOVE, this.onMouseMove);
Application.application.addEventListener(KeyboardEvent.KEY_DOWN, this.onKeyDown);
listeners = new Array();
}

/* Adds a listener to the listeners list */
public function addListener(listener:Object):Boolean{
for (var i:Number=0; i<listeners.length; i++){
if (this.listeners == listener) return false;
}
this.listeners.push(listener);
return true;
}

/* Removes a listener from the listener list */
public function removeListener(listener:Object):Boolean{
for (var i:Number=0; i<this.listeners.length; i++){
if (this.listeners == listener){
this.listeners.splice(i, 1);
return true;
}
}
return false;
}

/* Events */
private function onKeyDown(event:KeyboardEvent):void{
this.setIdleInterval();
}

private function onMouseMove (event:MouseEvent):void{
this.setIdleInterval();
}

/* Private Methods */
private function setIdleInterval():void {
this.__isActive = true;
clearInterval(this.intervalID);
this.intervalID = setInterval(this.broadcastIdle, this.idleTime);
}

private function broadcastIdle():void{
this.__isActive = false;
for (var i:Number=0; i<this.listeners.length; i++) {
this.listeners.onUserIdle();
}
clearInterval(this.intervalID);
}

}
}


How do i then make it so when the user is idle I can then call an mx:fade effect?

Thanks
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users