Jump to content
Search Community

flickScroll example - Button Click [HELP]

Applauz test
Moderator Tag

Recommended Posts

This is expanded on the flick/panel scroll example. .. What I am swiping through is movieclips and each movie clip has a button inside of it.

 

The problem I am having is that when you touch the button it gets picked up as a swipe. I've tried altering the values and can't get it to work for a touchscreen ie/ iPad. On the desktop the mouse is so precise that it's fine. This only happens on the iPad. Basically when I touch a button it thinks I swiped and moves to the next panel.

 

Here's my code.

 

 

var _panelBounds:Rectangle = new Rectangle(0, 0, 1024, 706);
var allChapters_mc:AllChapters_mc = new AllChapters_mc();

 this.addChild(allChapters_mc);
 allChapters_mc.x = _panelBounds.x;
 allChapters_mc.y = _panelBounds.y;


 var _currentPanelIndex:int = 0;
 var _panelCount:int;
 var _x1:Number;
 var _x2:Number;
 var _t1:uint;
 var _t2:uint;

 var blitMask:BlitMask = new BlitMask(allChapters_mc, 0, 0, 1024, 706, true);


 blitMask.bitmapMode = false;

 _panelCount = 29;

 blitMask.addEventListener(MouseEvent.MOUSE_DOWN, _mouseDownHandler, false, 0, true);



 function _mouseDownHandler(event:MouseEvent):void {
  trace("Mouse Down");


  TweenMax.killTweensOf(allChapters_mc);


  _x1 = _x2 = this.mouseX;
  _t1 = _t2 = getTimer();
  allChapters_mc.startDrag(false, new Rectangle(_panelBounds.x - 999999, _panelBounds.y, 99999999, 0));
  this.stage.addEventListener(MouseEvent.MOUSE_UP, _mouseUpHandler, false, 0, true);
  this.addEventListener(Event.ENTER_FRAME, _enterFrameHandler, false, 0, true);
 }

 function _enterFrameHandler(event:Event):void {
  _x2 = _x1;
  _t2 = _t1;
  _x1 = this.mouseX;
  _t1 = getTimer();
  blitMask.update();
 }

 function _mouseUpHandler(event:MouseEvent):void {

  trace("Mouse Up");
  allChapters_mc.stopDrag();
  this.removeEventListener(Event.ENTER_FRAME, _enterFrameHandler);
  this.stage.removeEventListener(MouseEvent.MOUSE_UP, _mouseUpHandler);
  var elapsedTime:Number = (getTimer() - _t2) / 1000;
  var xVelocity:Number = (this.mouseX - _x2) / elapsedTime;




  //we make sure that the velocity is at least 20 pixels per second in either direction in order to advance. Otherwise, look at the position of the allChapters_mc and if it's more than halfway into the next/previous panel, tween there.
  if (_currentPanelIndex > 0 && (xVelocity > 20 || allChapters_mc.x > (_currentPanelIndex - 0.5) * -_panelBounds.width + _panelBounds.x)) {
   _currentPanelIndex--;
  } else if (_currentPanelIndex < _panelCount - 1 && (xVelocity < -20 || allChapters_mc.x < (_currentPanelIndex + 0.5) * -_panelBounds.width + _panelBounds.x)) {
   _currentPanelIndex++;
  }
  if (allChapters_mc == null) {
   trace("---ERROR! Null target");
   return;
  }

  trace("CURRENT PANEL INDEX START = " + _currentPanelIndex);

  TweenMax.to(allChapters_mc, 0.7, {x:_currentPanelIndex * -_panelBounds.width + _panelBounds.x, ease:Strong.easeOut, onUpdate:blitMask.update,onComplete:setTitle});

 }

Link to comment
Share on other sites

strange i would think the xVelocity conditions would account for that.

how high of a tolerance have you set?

have you tried tracking the value of xVelocity? what number is it giving you for a button click?

Link to comment
Share on other sites

  • 3 months later...

Weird... I set it to 800 and now its working ;) Shouldn't have to be such a huge number though

 

Hello, this thread helped me too on that issue, however i have another issue that is similar. when i am swiping through my movieclips with buttons also, the buttons get fired accidentally. i need a away to remove the listeners while the movieclips are being dragged back and forth. ive exhausted google looking for the answer but nothing seemed to work or i wasnt doing it right which may be the case. i would like to know if any one has a solution, i'm pretty sure though that this a AS3 case and not GS

Link to comment
Share on other sites

  • 1 year later...

I think when folks were referring to setting the xVelocity they meant "checking to see if it was withing a certain threshold"

 

That code is already in place at the bottom:

 

if (_currentPanelIndex > 0 && (xVelocity > 20 || allChapters_mc.x > (_currentPanelIndex - 0.5) * -_panelBounds.width + _panelBounds.x)) {
    _currentPanelIndex--;
   } else if (_currentPanelIndex < _panelCount - 1 && (xVelocity < -20 || allChapters_mc.x < (_currentPanelIndex + 0.5) * -_panelBounds.width + _panelBounds.x)) {
    _currentPanelIndex++;
   }
 
Try changing the red 20s above to higher numbers.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...