Page 1 of 1

Problem with refresh images

Posted: Fri Oct 05, 2012 11:01 pm
by Neurox66
Hi,
in the background of my application the image change every 4 seconds .
If I stay in the same card, works well (Aren't exactly 4 seconds, but work.) If I go to another card and then return now start the problems, the pictures are running so syncopation and the image change every 1 or 2 seconds :shock:
Any hints?

my code:

Code: Select all

global gImmagine 
on preOpenCard
   put 1113 into gImmagine
end preOpenCard

on openCard
   send "aggiornaSfondo2" 
end openCard

on aggiornaSfondo2
   put gImmagine + 1 into gImmagine
   if gImmagine > 1118 then put 1113 into gImmagine
   set the backgroundPattern of card "cHome" to gImmagine
   send "aggiornaSfondo2" to me in 4 seconds
end aggiornaSfondo2

on closeCard
   lock messages
   repeat for each line 1 in the pendingMessages
      answer the pendingMessages
      cancel (item 1 of 1)
   end repeat
   unlock messages
end closeCard

Re: Problem with refresh images

Posted: Fri Oct 05, 2012 11:36 pm
by bn
Hi Neurox66,

try this

Code: Select all

on closeCard
   repeat for each line aMessage in the pendingMessages
      if aMessage contains "aggiornaSfondo2" then
         cancel (item 1 of aMessage)
      end if
   end repeat
end closeCard
that should work

Kind regards
Bernd

Re: Problem with refresh images

Posted: Sat Oct 06, 2012 12:20 pm
by Klaus
Or even better like this :D
Note my comments!

Code: Select all

global gImmagine 

LOCAL il_aggiornaSfondo2_messagio_id
## See below, what data this will hold
## I really like MEANINGFUL variable names ;-)

on preOpenCard
   put 1113 into gImmagine
end preOpenCard

on openCard
  ## No need to SEND anything, since the handler is "know" in the card script, so just call it
   aggiornaSfondo2
end openCard

on aggiornaSfondo2
   put gImmagine + 1 into gImmagine
   if gImmagine > 1118 then put 1113 into gImmagine
   set the backgroundPattern of card "cHome" to gImmagine

   ## Every SEND will get an ID under which it is managed in Livecode
   ## So we store this ID in a local variable and can then later simply CANCEL that ID
   ## See the closecard handler
   send "aggiornaSfondo2" to me in 4 seconds
   put the RESULT into il_aggiornaSfondo2_messagio_id
end aggiornaSfondo2

## Please look up SEND in the dictionary!

on closeCard
   cancel il_aggiornaSfondo2_messagio_id
  ## Done :-)
end closeCard
Best

Klaus

Re: Problem with refresh images

Posted: Sat Oct 06, 2012 4:32 pm
by Neurox66
Ciao Bernd and Klaus,
Thanks for the clear full explanation.

Paolo