///////////////////////////////////////////////////////////////////////////////////////////////////
//
// onDoubleClick-event
// ===================
//
// This Script adds an onDoubleClick-event to the MovieClip-Class.
//
// usage:
// mcBall.onDoubleClick = function () {
// trace('I was double-clicked');
// }
//
// attention:
// If you want to remove the double-click-behaviour set it to null,
// delete will not work.
// mcBall.onDoubleClick = null;
//
// side-effects:
// If you need the: "onPress-Handler" you have to define it first,
// otherwise the onDoubleClick-event stops working.
//
// In MovieClips that use the onDoubleClick-Event the following properties
// are settet:
// __onPress__
// __lastClick__
// __onDoubleClick__
// These properties are hidden by ASSetPropFlags.
//
///////////////////////////////////////////////////////////////////////////////////////////////////
onDoubleClickGetter = function () {
return this.__onDoubleClick__;
}
//
onDoubleClickSetter = function (pNewValue) {
if (pNewValue == null) {
this.__onDoubleClick__ = undefined;
this.onPress = this.__onPress__;
return;
}
//
if (this.__onDoubleClick__ != undefined) {
this.__onDoubleClick__ = pNewValue;
return;
}
//
this.__onDoubleClick__ = pNewValue;
this.__lastClick__ = null;
//
this.__onPress__ = this.onPress;
this.onPress = function () {
// The 500 is the DoubleClick-Time, add your hook here.
if (this.__lastClick__ + 500 > getTimer()) {
this.__onDoubleClick__();
this.__lastClick__ = this.__lastClick__ - 500;
} else {
this.__onPress__();
this.__lastClick__ = getTimer();
}
}
//
ASSetPropFlags(this, ['__onPress__', '__lastClick__', '__onDoubleClick__'], 1, 0);
}
//
MovieClip.prototype.addProperty('onDoubleClick', onDoubleClickGetter, onDoubleClickSetter);
//
delete onDoubleClickGetter;
delete onDoubleClickSetter;
// Test
/*
mcBall.onPress = function () { trace('onPress'); }
mcBall.onDoubleClick = function () {
trace('onDoubleClick');
}
*/