okay, so i have a prototype for drag and rotate:
MovieClip.prototype.drag = function() {
this.i = 0;
this.ease = 10;
this.onPress = function() {
this.startDrag(false);
this.swapDepths(1);
this.onEnterFrame = function() {
if (this.i == 0) {
this.oldX = _xmouse;
trace(oldX);
this.i++ ;
}
this.newX = _xmouse;
this.verschil = this.newX-this.oldX;
this._rotation += (10+this.verschil-this._rotation)/this.ease;
this.oldX = this.newX;
};
};
this.onRelease=onReleaseOutside= function() {
this.stopDrag();
this.onEnterFrame = function() {
this._rotation += (0-this._rotation)/this.ease;
if (Math.abs(this._rotation)<0.1) {
this._rotation = 0;
delete this.onEnterFrame;
}
};
};
and i’m checking if there’s a double click:
// previous mouse coordinates
var previouspos: Object = {x: 0, y: 0};
// time of previous click
var previoustime: Number = getTimer();
onMouseDown = function() {
// get coordinates of current click
var newpos: Object = {x: _xmouse, y: _ymouse};
// get time of current click
var newtime: Number = getTimer();
// if the new coordinates are within 2 pixels of the old coordinates
// and the new time is within half a second of the old time
if ( (abs(previouspos.x - newpos.x) <= 2) &&
(abs(previouspos.y - newpos.y) <= 2) &&
((newtime - previoustime) < 500) ) {
trace("double click at " + newpos.x + "," + newpos.y);
this._rotation = 0;
} else {
trace("click at " + newpos.x + "," + newpos.y);
};
// save new pos and time as previous pos and time
previouspos = newpos;
previoustime = newtime;
}
};
and making it work:
myclip.onPress=function(){
this.drag();
}
now my problems. 1) without the doubleclicking, i need to click once on the movie clip to “activate” it or something, and then click again to drag it. shouldn’t it work right away on the onPress event? and 2) i would like to add some doubleclick functionality, but when i try and add a double click, i can trace it, but if i try to do anything with it, the doubleclick functionality seems to be overridden by two single clicks … logically, because i didn’t check for the doubleclick at all in the drag script. i’m not sure where i should add the doubleclick stuff… i’ve tried putting it a few different places and either i get two single clicks, or my scope is way wrong and i wreck the drag stuff.
i could totally use some help, guys.