Jan 13
UserInteraction class - sets off a timer after you leave a designated user area onstage and fires a callback a function. Very useful for banners.
Where I work we do alot of banners. I wrote a class a while back that has come in handy multitudes of times. It contains a handful of public functions and I’ve used it on many major advertising banner campaigns (various HP banners, Snickers – Get Some Nuts, Toyota Sequoia, etc).
EXAMPLE SITUATIONS:
- Suppose you want to set a timer after a user has rolled out of a banner and then call a function to have an animation play out to the end once the time is up.
- Suppose you want a popup window in your website to remain open for 3 seconds after the user has left the hit area, and then close. But if the user rolls over the area before the time is up the user interaction area resets itself.
HOW TO USE IT:
//—————————————————————————
import UserInteraction;
var objUserInteraction:UserInteraction = UserInteraction.getInstance();
function endFunc() {
trace(’endFunc called’);
objUserInteraction.reset();
}
objUserInteraction.setup({clip:mcClip, timer:3, show:true, timerCallback:{scope:this, func:”endFunc”}});
//—————————————————————————
- Import the class
- Create an instance of it
- Create a MovieClip of the desired hit state area and name it
- Create a function that the class will call at the end of timer
- Call the setup function
AVAILABLE PUBLIC FUNCTIONS:
METHOD
getInstance():UserInteraction
Creates a new instance of the class.
————————————–
METHOD
setup($obj:Object):Void
Passes all the necessary variables into class.
PARAMS
$obj : Pass an object of the following params:
clip: MovieClip that will be used as hit area.
timer: Time set in seconds.
timerCallback: Function that is called once the user has been out of the area for designated time.
rollOverCallback (optional): Function that can be called on rollover.
show (optional): When set to true will make the MovieClip visible at 50% alpha. Default is set to false.
————————————–
METHOD
reset():Void
This allows the hit area to be used again after the timer condition has been met.
————————————–
METHOD
stop():Void
This stops all functionality at work in the class and also hides hit area.
SIDE NOTES:
- You may want to keep the hit area a bit smaller than the actual target area especially with banners. This is suggested because if the user rolls out of the area too quick, Flash may think that the mouse is still over the hit area and the timer will not be started.
- Always scale the contents of a MovieClip and not the MovieClip as a whole from the outside. You may get undesired results other wise.
No Comments
Leave a comment