Copy link to clipboard
Copied
Hi,
I'm trying to use two code snippets in the same app I'm working on.
The code snippets are swipe and zoom. So I've got an image gallery which swipes perfectly. Then on another frame I've got an image that I want to pinch and zoom in on.
If I go to either of those first they both work fine. The problem occurs when I go to one after the other.
So if I go to the image I want to zoom in on first that works fine. But when I go to the frame with the gallery I want to swipe left and right on afterwards, it stops working.
And it happens vice versa: if I go to the swipe gallery first, it works fine. But when I go to the zoom image, that stops working.
Here's the code I'm using:
For the zoom image:
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_ZOOM, fl_ZoomHandler1);
function fl_ZoomHandler1(event:TransformGestureEvent):void
{
bike_mc.scaleX *= event.scaleX;
bike_mc.scaleY *= event.scaleY;
}
For the swipe gallery:
Multitouch.inputMode = MultitouchInputMode.GESTURE;
var currentGalleryItem:Number = 1;
var totalGalleryItems:Number = 4;
gallery_items.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeToGoToNextPreviousFrame);
function fl_SwipeToGoToNextPreviousFrame(event:TransformGestureEvent):void
{
if(event.offsetX == 1)
{
if(currentGalleryItem > 1){
currentGalleryItem--;
slideRight();
}
}
else if(event.offsetX == -1)
{
if(currentGalleryItem < totalGalleryItems){
currentGalleryItem++;
slideLeft();
}
}
}
var slideCounter:Number = 0;
function slideLeft(){
gallery_items.addEventListener("enterFrame", moveGalleryLeft);
}
function slideRight(){
gallery_items.addEventListener("enterFrame", moveGalleryRight);
}
function moveGalleryLeft(evt:Event){
gallery_items.x -= 48;
slideCounter++;
if(slideCounter == 10){
gallery_items.removeEventListener("enterFrame", moveGalleryLeft);
slideCounter = 0;
}
}
function moveGalleryRight(evt:Event){
gallery_items.x += 48;
slideCounter++;
if(slideCounter == 10){
gallery_items.removeEventListener("enterFrame", moveGalleryRight);
slideCounter = 0;
}
}
"
Thanks for any ideas in advance.
Copy link to clipboard
Copied
if that code were on one frame with no other code there would be no problem. because there is other code and frame changes that (esp the frame changes) could cause a problem with bike and gallery_items not being defined (the way you want) after frame changes.
Copy link to clipboard
Copied
Hi and thanks for your feedback.
I guessed it was something like that so I'm thinking of putting the image I want to zoom in on in an external swf.
My thinking is that way it would avoid any conflict, the code for the pinch and zoom would be entirely on another timeline and be the only code snippet on that timeline.
But this raises other questions:
When I publish the app, how will I include the external swf - by putting on my server for example and linking to it via url or include it somehow in publish settings?
Or is this idea just a idea?
Thanks again.
Copy link to clipboard
Copied
i assume you're creating an air project. if so, you would add your swf to the 'included' files in your air publish settings.
but i wouldn't recommend that because, while it would solve your problem, it won't be any significant advantage over simpler ways to use code to add and remove bike and gallery_items.
ie, adding and removing bike and gallery_items using code (addChild and removeChild) instead of using the timeline, almost certainly, will solve your problem.
Copy link to clipboard
Copied
OK great thanks.
I'll have a look at what you suggest. I've never used add/removeChild function.
I may be back . . .
thanks again.
Copy link to clipboard
Copied
you're welcome.
Find more inspiration, events, and resources on the new Adobe Community
Explore Now