Copy link to clipboard
Copied
Hi everyone!
I'm design a project for touch interfaces and on my project I have a scrollpane with scrolldrag = true and the source is a sprite with buttons.
My problem is that when I drag my scrollpane the mouse click event on the button is triggered. How can I easily prevent this from happening?
Best regards,
Daniel Sousa
Set the mouseChildren property of your scrollpane content to false until the mouseup occurs...
sp.source = mc;
sp.addEventListener(ScrollEvent.SCROLL, holdBtns);
function holdBtns(evt:ScrollEvent):void {
mc.mouseChildren = false;
}
sp.addEventListener(MouseEvent.MOUSE_UP, endIt);
function endIt(evt:MouseEvent):void {
mc.mouseChildren = true;
}
Copy link to clipboard
Copied
One way that might work would be to make use of the ScrollEvent.SCROLL that should be happening when you scroll. You should be able to somehow disable your buttons when the scrolling event is detected and then re-establish their use when the drag interaction ends. I am not familiar with how the touchscreen deals with releasing the drag, but normally with a mouse a MOUSE_UP would do it.
Copy link to clipboard
Copied
I'm using click events for the touch screen anyway.
I've already thought that, but the problem is that each button calls a different function on the main class, so I'd need to add an ugly check on each function. I'd like to find a cleaner way, but I can always do that if it's really needed...
Copy link to clipboard
Copied
Set the mouseChildren property of your scrollpane content to false until the mouseup occurs...
sp.source = mc;
sp.addEventListener(ScrollEvent.SCROLL, holdBtns);
function holdBtns(evt:ScrollEvent):void {
mc.mouseChildren = false;
}
sp.addEventListener(MouseEvent.MOUSE_UP, endIt);
function endIt(evt:MouseEvent):void {
mc.mouseChildren = true;
}
Copy link to clipboard
Copied
Thank you very much! That solution works really well! ![]()
I wasn't able to work with the scrollEvent, so I used your idea but only with MouseEvents. Here's my code:
public class scrollpaneObject extends MovieClip {
public var sprite:Sprite = new Sprite();
private var dragging:Boolean = false;
private var clicking:Boolean = false;
public function scrollpaneObject() {
addEventListener(MouseEvent.MOUSE_DOWN,startClick);
addEventListener(MouseEvent.MOUSE_MOVE,startDragging);
addEventListener(MouseEvent.MOUSE_UP,stopClick);
addEventListener(MouseEvent.MOUSE_OUT,stopClick);
}
private function startClick(e:Event):void {
clicking = true;
}
private function startDragging(e:Event):void {
if(clicking==true){
mouseChildren = false;
dragging = true;
}
}
private function stopClick(e:Event):void {
if(dragging==true && e.target==this){
clicking = false;
dragging = false;
mouseChildren = true;
}
}
}
Copy link to clipboard
Copied
You're welcome
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more