Conflict between on closecard handlers? (for iOS)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
stjones
Posts: 13
Joined: Fri Dec 12, 2014 3:52 am

Conflict between on closecard handlers? (for iOS)

Post by stjones » Sun Dec 21, 2014 2:23 am

I have a stack (STACK ONE) and a sub-stack (STACK TWO). I have a button in STACK ONE that takes me to the first card of STACK TWO with the script:

Code: Select all

on mouseUp
   visual effect "push left very fast"
   go to card 1 of stack "education_images"
end mouseUp
This STACK TWO consists of about a dozen cards, each with a large main image on them. I have scripted it (with the help of other kind folks in this forum) so you can swipe between cards/main images. Each card has a button named BACK on it and a button named INFO on it. When you click the INFO button, an information image slides up from the offscreen bottom with information about the main image in it. When you click INFO again, the information image slides back down off the screen. In the closecard handler I have the script:

Code: Select all

on closecard
  lock screen for visual effect
   set the loc of image "education_info_1" to 160,819
   put "false" into isUpVar
unlock screen with" push right very fast"
end closecard
The idea in this closecard handler is to move the information image back to it's off screen position if the user swipes to the next card without dismissing the information image by pressing the INFO button the second time.


When you click the BACK button, it is to take you back to the card in STACK ONE that brought you into STACK TWO. Its script is:

Code: Select all

on mouseUp
   lock screen for visual effect 
   go to card "portfolios" of stack "MSI"
   unlock screen with push right very fast
end mouseUp
But for some reason instead of getting the PUSH effect, the stack just JUMPS back to the card in STACK ONE when you select the BACK button.

I have the feeling the problem is a conflict between the BACK script executing and also triggering the on closecard handler script of the card containing the BACK button. But I can't seem to figure out a fix.

Any suggestions?

Thanks!

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Conflict between on closecard handlers? (for iOS)

Post by dave.kilroy » Sun Dec 21, 2014 12:01 pm

Hi - I can't really tell without tinkering with your code but I should think the reason you are seeing a 'jump' is because you have two 'visual effect' statements running.

I also think you are making things more complicated for yourself than you need to by putting a visual effect in a closecard handler, I would put visual effects in the 'action' or calling script (or reference visual effects from the calling script) - like you've done with your button in the first stack and the BACK button in your second stack.

You are right to put something in the closecard handler that moves the information image if its showing, but I think you should be able to simply set it's loc to the down position as long as you've already got an 'unlock screen with visual effect' in your 'calling' script:

Code: Select all

on closecard
  if the loc of img tImage = tUpPosition then set the loc of img tImage to tDownPostion
end closecard
With any luck you'll now find that the information image is removed gracefully inside the visual effect called in your BACK button.

As to how you would now get a swipe effect when you've removed 'visual effect' from the closecard handler - if you are not already using something to give you a visual effect you could use the following in the stack script of your second stack:

Code: Select all

local sStartH
on mousedown
   put the mouseH into sStartH
end mousedown

on mouseUp
   if abs(the mouseH - sStartH) > 50 then
       if the mouseH < sStartH then
           goNext
       else
           goPrevious
       end if
   end if
end mouseUp

on goNext
   if the short name of the current cd <> "cdLastCard" then
      lock screen      
      go next cd
      unlock screen with visual effect "push left" very fast
   end if
end goNext

on goPrevious
   if the short name of the current cd <> "cdFirstCard" then
      lock screen      
      go previous cd
      unlock screen with visual effect "push right" very fast
   end if
end goPrevious
And of course make sure you change "cdFirstCard" and "cdLastCard" to suit your stack

WARNING: I haven't checked all of this code so watch out for misspellings and bugs!

Dave

EDIT: oops, just corrected an error in the closecard handler
"...this is not the code you are looking for..."

Klaus
Posts: 14199
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Conflict between on closecard handlers? (for iOS)

Post by Klaus » Sun Dec 21, 2014 12:41 pm

Hi all,

Code: Select all

on mouseUp
   lock screen for visual effect 
   go to card "portfolios" of stack "MSI"
   unlock screen with push right very fast
end mouseUp
is this really working? :shock:
Visual effects are supposed to only work inside of a stack and not when going from one stack to another!?

And instead of wondering what is happening, why not just MOVE the image "education_info_1" out of sight again? :D


Best

Klaus

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Conflict between on closecard handlers? (for iOS)

Post by dave.kilroy » Sun Dec 21, 2014 1:09 pm

Hey Klaus - good point about visual effects and stacks! As for MOVING the image, I already suggested setting it's loc...

Dave
"...this is not the code you are looking for..."

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Conflict between on closecard handlers? (for iOS)

Post by Dixie » Sun Dec 21, 2014 2:50 pm

Klaus..

from the 'visual effect' entry in the dictionary...
'The visual effect command affects only navigation within a window. If you want to create a transition effect when moving between stacks, use the go...in window form of the go command:'
Dixie

dave.kilroy
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 858
Joined: Wed Jun 24, 2009 1:17 pm
Contact:

Re: Conflict between on closecard handlers? (for iOS)

Post by dave.kilroy » Sun Dec 21, 2014 3:49 pm

Well done Dixie :)

I've now reread the 'visual effect' entry in the dictionary :oops:
"...this is not the code you are looking for..."

stjones
Posts: 13
Joined: Fri Dec 12, 2014 3:52 am

Re: Conflict between on closecard handlers? (for iOS)

Post by stjones » Sun Dec 21, 2014 11:11 pm

Thanks all for the replies. Once again, with your help I got things back on track and working. A few comments:

1) @dave - Thanks for the pointer on simplifying the "loc" command

2) @klaus - I didn't know visual effects didn't work between stacks (until Dixie pointed out the solution in the dictionary). And I WAS trying to move the image. That was part of the problem.

3) @dixie - Thanks for the heads up on the visual effects "fine print" in the dictionary.

Post Reply