Skip to main content
This topic has been closed for replies.

2 replies

Known Participant
October 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.

kglad
Community Expert
Community Expert
October 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?

}

Known Participant
October 16, 2015

kglad‌ It works perfectly..

kglad
Community Expert
Community Expert
October 5, 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

Known Participant
October 14, 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.

Known Participant
October 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();

}