Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Drag scrollpane triggers click events

Guest
Sep 01, 2011 Sep 01, 2011

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

TOPICS
ActionScript
1.2K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Sep 01, 2011 Sep 01, 2011

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;
}

Translate
LEGEND ,
Sep 01, 2011 Sep 01, 2011

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 01, 2011 Sep 01, 2011

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...

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 01, 2011 Sep 01, 2011

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;
}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 01, 2011 Sep 01, 2011

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;

}

}

}

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Sep 01, 2011 Sep 01, 2011
LATEST

You're welcome

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines