views:

22

answers:

1

I am working on a little project, what's goal is a working widget system in Flash - by creating a separate class, and loading Flash movies into this, then dragging them around the screen.

I ran into a little problem when I was writing the dragging code: I can not found any code what can easily get the time from the function call. To be more precise, I want the container only draggable after 2 seconds of continuous press, and that's what I am trying to detect.

Is there any easy solution?

+1  A: 
Timer pressTimer = new Timer(2000);
pressTimer.addEventListener(TimerEvent.TIMER, onTimer);
container.addEventListener(MouseEvent.MOUSE_DOWN, onMouseDown);
container.addEventListener(MouseEvent.MOUSE_UP,onMouseUp);
function onMouseDown(e:MouseEvent):void {
  pressTimer.start();
}
function onMouseUp(e:MouseEvent):void {
  pressTimer.reset();
}
function onTimer(e:TimerEvent):void {
  pressTimer.reset();
  //do the dragging and stuff.
}
bhups
Thanks, but unfortunately it did not work. Maybe it is a problem I am trying to do it in Flash Lite 2?
fonix232
what kind of errors / unexpected behavior your are getting?
bhups
First of all, it won't even compile. Some problems with the first presstime.addEventListener, and it should not active on mouse down, but on press and release (for touch screens).
fonix232