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

How to stop Touch or Click Event while Swipe Event is in action?

Community Beginner ,
Oct 05, 2015 Oct 05, 2015

How to stop Touch or Click Event while Swipe Event is in action?

TOPICS
ActionScript
1.6K
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
Community Expert ,
Oct 05, 2015 Oct 05, 2015

depending on the two events you can sometimes just use e.stopImmediatePropagation() in the swipe listener function (where e is the swipe event).  but sometimes (if the touch or click event is dispatched first) you have to alter your listeners, with the swipe listener using capture

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
Community Beginner ,
Oct 13, 2015 Oct 13, 2015

kglad‌ Thanks for the reply. As I'm a beginner in as3

RTN9Q.png

In my Main.as

     var tileMap:Dictionary = new Dictionary();

     public var tile:ImageTile; 

     addChild(wall);

     var images:XMLList;

     var total:Number;

     var swipe:Number = 0; 

     var myXMLLoader:URLLoader = new URLLoader();

     myXMLLoader.load(new URLRequest("gallery.xml"));

     myXMLLoader.addEventListener(Event.COMPLETE, processXML); 

     stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);

     function processXML(e:Event):void {

          myXML = new XML(e.target.data); 

          images = myXML.IMAGE;

          total = images.length(); 

          myXMLLoader.removeEventListener(Event.COMPLETE, processXML);

          myXMLLoader = null;  

          var loader:Loader;

          for (var i:uint = 0; i < total; i++)

          {

            tile = new ImageTile();

            wall.addChild(tile); 

            tile.x = i % 3 * 400 + 180;

            tile.y = Math.floor(i / 3) * 650 + 250; 

            var imageName:String = images[i].@FULL;

            path = images[i].@Path;

            var title:String = images[i].@Title;

            var caption:TextField = tile.getChildByName("caption_tf") as TextField;

            caption.text = title;

            tile.addEventListener(MouseEvent.CLICK, showBook());

            loader = new Loader();

            loader.load(new URLRequest("images/" + imageName));

            tileMap[loader] = tile;

            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onImageLoad);

            }

           }  

      

        function onImageLoad(e:Event):void

        {

          var loader:Loader = e.target.loader;

          var tile:ImageTile = tileMap[loader] as ImageTile;

          var image:Bitmap = loader.content as Bitmap;

          image.x = -100; image.y = -100;

          image.width=366; image.height=418;

          var textField:DisplayObject = tile.getChildByName("caption_tf");

          var textFieldDepth:int = tile.getChildIndex(textField);

          tile.addChildAt(image, textFieldDepth);

          tileMap[loader] = null; image.smoothing = true;

        }


     public function fl_SwipeHandler(event:TransformGestureEvent):void

       {

         switch(event.offsetY)

         {

            // swiped down

            case 1:

            {

            if (swipe!=0){

                 Tweener.addTween(wall, {y: wall.y + 650, time:.5, transition:"easeOutSine" } );

                 swipe--;

                 }

            // End your custom code

            break;

            }

            // swiped up

            case -1:

            {

            if (swipe<=(total/5)){

                 Tweener.addTween(wall, { y: wall.y - 650, time:.5, transition:"easeOutSine" } );

                 swipe++;

                 }

            // End your custom code

            break;

            }

        }

  }


This is the code. Here i have to swipe the wall and click the tile to open a book.

But it happens at same time. Please help me.

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
Community Beginner ,
Oct 14, 2015 Oct 14, 2015

Now I even used Stoppropogation()

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler, true, 1);

tile.addEventListener(MouseEvent.CLICK, showBook, false, -1);

public function showBook(MouseEvent):void

  {

e.stopImmediatePropagation();

}

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
Community Beginner ,
Oct 14, 2015 Oct 14, 2015

@nezarov Sorry i didn't mention e in my previous reply

public function showBook(e:MouseEvent):void {

e.stopImmediatePropagation();

}

My code was like this only,

@deleted reply

Also I couldn't use onComplete:showBook at tweener, because each tile has its own thumbnail, title, filepath (for book). If i remove the mouse click eventlistener for tile, then i couldn't get the file path of the tile, the user touched.

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
Community Expert ,
Oct 14, 2015 Oct 14, 2015

you can stop the swipe event or the click event using stopPropagation(), but those aren't the same event so stopping one isn't going to affect the other.

you can use a boolean:

var stopClickBool:Boolean=false;

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler, true, 1);

tile.addEventListener(MouseEvent.CLICK, showBook, false, -1);

public function fl_SwipeHander(e:TransformGestureEvent):void

  {

stopClickBool=true; 

}

function showBook(e:MouseEvent):void{

if(!stopClickBool){

// your click handler code

}

// reset stopClickBool?

}

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
Community Beginner ,
Oct 16, 2015 Oct 16, 2015

kglad‌ It works perfectly..

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
Community Beginner ,
Oct 16, 2015 Oct 16, 2015

Can you answer me one more question? Actually showbook() opens a starling, when we come to the main screen after starling.dispose(), TransformGestureEvent is not working. I even used stage.removeEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler); inside showbook()  and added stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler); inside the function

public function onKeyDown(event:KeyboardEvent):void

  {

  if(event.keyCode == Keyboard.BACK )

  {

sage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler);

///

  }

}

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
Community Expert ,
Oct 16, 2015 Oct 16, 2015
LATEST

if you used,

stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler, true, 1);

to add the listener, use

stage.removeEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler, true);

to remove it.

as for the effect of starting, i don't really know.

(p.s when using the adobe forums, please mark helpful/correct responses, if there are any.)

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