AS3 Click Handler – How to limit click occurrence
I’ve always found the way flash treats a click-event quite annoying.
No matter when you release the left mouse-button, flash will always trigger a Click-Event, even if you keep waiting for seconds.
In its original matter, clicking was meant to be a short order of Pressing the Mouse Down and letting go of it!
Furthermore I wouldn’t want to have the system fire a Click-Event when moving a particular amount of pixels in between my Mouse-Down and Mouse-Up phases!
To meet these needs I wrote myself a Class that would handle all the forespoken concepts!
package Global.Utils {
import flash.events.MouseEvent;
import flash.geom.Point;
import flash.display.DisplayObject;
public class ClickHandler {
public static var ClickMaxMove:Number = 5;
public static var ClickMaxTime:Number = 100;
private var StoreMousePosition:Point;
private var StoreTime:Number;
public function ClickHandler(StageInstance:DisplayObject) {
StageInstance.stage.addEventListener(MouseEvent.MOUSE_DOWN, OnMouseDown, true);
StageInstance.stage.addEventListener(MouseEvent.CLICK, OnClick, true);
}
private function OnMouseDown(event:MouseEvent):void {
StoreMousePosition = new Point(event.currentTarget.stage.mouseX, event.currentTarget.stage.mouseY);
StoreTime = new Date().getTime();
}
private function OnClick(event:MouseEvent):void {
var Distance:Number = Math.abs(StoreMousePosition.x - event.currentTarget.stage.mouseX) + Math.abs(StoreMousePosition.y - event.currentTarget.stage.mouseY);
if (Distance > ClickMaxMove) Stop(event);
if ((StoreTime - new Date().getTime()) > ClickMaxTime) Stop(event);
}
private function Stop(event:MouseEvent):void {
event.stopImmediatePropagation();
event.stopPropagation();
event.preventDefault();
}
}
}
You can call this ClickHandler at any time by passing it the stage or any child that’s already been added to the stage!
For the purpose of this Handler you should respectively call it at the beginning of your Application!
Still, no need to keep an instance of it, since all important events will be added to the main stage.
By keeping the Core-Variables ClickMaxMove and ClickMaxTime static you can Adjust them when needed during runtime (e.g. User-Settings, PHP-Query-String, etc.)
import Global.Utils.ClickHandler; new ClickHandler(stage); ClickHandler.ClickMaxMove = 10; ClickHandler.ClickMaxTime = 200;
Any questions, comments and further suggestions for improving this Class are welcome and appreciated!
Freebie: AS3 Image Loader Class
Free Preloader
I found myself writing the same piece of code over and over again.
So i finally decided to put it into a single class, that fits my needs!
The class provides you the ability to simply load images, display their loading stat through a native preloader and process the image for further use!
In hope that you might find it useful I’m sharing this class now with you.
Customize
The class can be customized down to the following:
- Decide wheter to show a preloader or not
- Force the image size
- Setting colors
- Display a framing
Read the full documentation provided in the file ImageLoader.as for more information!
The class requires to have the TweenLite engine in your main file directory.
For avoiding troube please get it from greensock! Download TweenLite
If you find Bugs or unusual behavior occurs, please contact me!
Sample
Grandmaster Tigga – in memoriam
Just look how cute Tigga was! I’m so sad he’s gone now, really miss him a lot! ![]()
Sometimes he was some mean ass, as you can see, but you really couldn’t resist these eyes!
I really adored this cat. Do you?
@fmx 2010
We’ve been at Stuttgart on the 5th and 6th May, attending this years fmx – conference on visual effects and animation.
Starting from Innsbruck at 3 am we really got pretty much tired in the train.
Finally arrived at Stuttgart we made up our way directly to the conference.
If you ask me, this year there was way too much about stereoscopic 3D and Avatar – some may like it, but i still find it a big hype!
But of course there also were some good classes and workshops.
I really enjoyed the speech of pure. Was kind of opening my and some other guys eyes.
All in we absolutely had our fun during this two days and have seen a lot, so i guess…
…see you again in 2011
@wildruf
A day at Wildruf can be quite exciting, most of all when it comes to check out their camera, the almighty – red – Evil monster I gotta tell you!
We’ve been invited to get our hands on their equipment for a day!
Check out their website for more information about their work!
I was up there taking some impressions of what we were doing.
If it just wasn’t so terribly cold… :/
Shooting Young Lions 2010 – woman helpline
This year’s Young Lions – Competition for Young Creatives – topic was to create an immersive print campaign for a woman helpline!
We’ve been on a shooting, trying to get an emotive, sad looking picture of a young woman that should give the impact of violence!
Our goal was to have it look cold and painful.
We had to try out a few different patches and several viewpoints to find out what could look best.
After taking a load of pictures we finally decided, that we’d go with the very last shot I took!
Later on I took the picture to Camera Raw for some basic color correction and did some very simple postwork in Photoshop to finally get the look that we wanted.
You can see the final output and our print campaign at the end of this gallery!
At least we had some fun during this shooting as you can see in the pictures
You can see all the final submissions here

















































































































































































