Home Tutorials Forums Articles Blogs Movies Library Employment Press

Go Back   ActionScript.org Forums > Flex > Flex 2, 3 & 4

Reply
 
Thread Tools Rate Thread Display Modes
Old 06-22-2006, 01:42 PM   #1
jorishilhorst
Registered User
 
Join Date: Jun 2006
Posts: 2
Default Anyone managed to get drag and click to work seperate from one another?

Hi,

I am trying to use the dragmanager with an element, but at the same time support onClick to allow the element to be selected. I'm not sure if this is flex2 specific (but am using the latest version)

in the attributes of the object I have put:
click="clickHandler(event)"
mouseDown="dragThumbnail(event)"
and inside the script block I have defined the following functions:
public function clickHandler(event:MouseEvent):void {
parentApplication.setSelectedPhone(this);
}

public function dragThumbnail(event:MouseEvent):void {
var ds:DragSource = new DragSource();
ds.addData(this, dragType);

DragManager.doDrag(IUIComponent(this), ds, event);
}
This works after a fashion, as the mouseclick gets caught, and on mousedown the canvas gets dragged around. However does anyone know how I can make sure the dragThumbnail method does not start in the case of a mouseclick?
The problem is that the drag action always starts (even on a regular mouseclick).

I was thinking of making a timer which polls or something but that seems like hacking to me. Anyone have any thoughts?

cheers,
joris
jorishilhorst is offline   Reply With Quote
Old 06-23-2006, 09:35 AM   #2
jorishilhorst
Registered User
 
Join Date: Jun 2006
Posts: 2
Default One part of the problem fixed

Heya, I managed to figure part of this out:

I'm not 100% sure I won't run into synchronisation issues with the mouseUpHandler and the timerEventHandler interfering with one another, perhaps someone can give me some advice on it.

Code:
        private var timer:Timer;
        private var mouseDownEvent:MouseEvent;
        public function clickHandler(event:MouseEvent):void
        {        	
        	parentApplication.setSelectedPhone(this);
        	// this is a click (so shouldn't be a drag)
        }
		
	public function mouseDownHandler(event:MouseEvent):void {
		if (timer != null && timer.running) {
			// timer was already running, we reset it
			timer.stop();
			timer.removeEventListener("timerComplete", dragThumbnail);
			timer.reset();
		} 
		timer = new Timer(100, 1);
		timer.addEventListener("timerComplete", dragThumbnail);
		timer.start()
		mouseDownEvent = event;
	}
	public function mouseUpHandler(event:MouseEvent):void {
		if (timer.running) {
			timer.stop();
			timer.removeEventListener("timerComplete", dragThumbnail);
		}
	}
        public function dragThumbnail(timer:TimerEvent):void {
	   	var ds:DragSource = new DragSource();
         	ds.addData(this, dragType);
         	
         	DragManager.doDrag(IUIComponent(this), ds, mouseDownEvent);
         	DragManager.showFeedback(DragManager.MOVE);
      	}
There is an additional issue, which I think is listed in the flash 9 known bug list: if the mouse does not move, the DragManager will be in a weird state.
(so click, hold, release will actually result in a dragComplete but not a dragDrop.) As I had used an online example that implemented 'to remove the element from a list, drag it outside of the area' which actually uses dragComplete, this now fires if the mouse has not moved. (so click, hold, release causes the element under the mouse to go away).

Does anyone know a workaround for that bug? (if i'm not being clear I can try to make a code example for it)

cheers,
joris
jorishilhorst is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
as2 and double click / drag detection huwn ActionScript 2.0 7 06-19-2007 04:36 PM
combine button double click with drag function ahungryghost ActionScript 2.0 2 01-27-2006 04:35 AM
Click & Drag dosent work after a new scene has been added!! DanielHusk ActionScript 2.0 0 04-08-2004 06:30 AM
click or drag // menus ???? Motion2082 Other Flash General Questions 2 09-08-2003 04:12 PM
Help needed in Click & drag jtb_india Animation and Effects 4 04-18-2002 10:03 AM


All times are GMT. The time now is 03:45 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.