changing images on a card

LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
mickus
Posts: 3
Joined: Tue Sep 08, 2009 5:42 am

changing images on a card

Post by mickus » Tue Sep 08, 2009 5:49 am

Hi All,

I am completely new to programming and need to get an application up and running in a few weeks. I need an image to change every few seconds to another image and so on. Does anyone know how I can set this up, or what steps I need to go through??

Any help would be much appreciated!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Sep 08, 2009 9:00 am

Dear Mickus,

As a start, create a folder with a bunch of small pictures and try the following in a checkbox button. For now, please make sure that the folder only contains pictures that Revolution can read.

Code: Select all

on mouseUp
  if the hilite of me then
    answer folder "Select a folder with pictures files only"
    if it is not empty then
      set the defaultFolder to it
      showPict
    end if
  else
    put the pendingMessages into myMessages
    filter myMessages with "showPict"
    repeat for each line myLine in myMessages
      cancel item 1 of myLine
    end repeat
  end if
end mouseUp

on showPict
  put any line of the files into myFile
  set the filename of img 1 to myFile
  if the hilite of me then send showPict to me in 5 secs
end showPict
Make sure to save the stack before you click the button. I didn't test this code, please mind typos. Let me know how it goes.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

mickus
Posts: 3
Joined: Tue Sep 08, 2009 5:42 am

Post by mickus » Tue Sep 08, 2009 11:12 am

Hi Mark,

Thanks heaps for your response. I have tried it, and when I click the button it opens the file on my desktop so that I can then select from the pics in the file. Do you know how I can make it so that an image appears, and then after a second it changes to another image and then another etc?. Sorry, but am finding it hard to grasp all the scripting language!

Mark
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5150
Joined: Thu Feb 23, 2006 9:24 pm
Contact:

Post by Mark » Tue Sep 08, 2009 12:08 pm

Dear mickus,

That's exactly what the script does. Perhaps you should read my previous message again and give it another try.

Best,

Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers
The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Tue Sep 08, 2009 12:12 pm

Make sure you have an image area on your card which can display the image that you populate the filename with in the showPict handler.

Otherwise, make sure that you don't repeatedly click the checkbox, or it will turn off the display!

Oh, and the dialogue box is just for you to select the folder containing the images - you don't select any image files inside that folder. Just use that dialogue to let rev know where the images are kept and it will use that location for the rest of the automatic display.

mickus
Posts: 3
Joined: Tue Sep 08, 2009 5:42 am

Post by mickus » Wed Sep 09, 2009 4:47 am

I didn't have an image box displayed on the card for the images to be visible in - thanks for the heads up SparkOut.

Thanks again for the script Mark - I have tried it again and it works well, however before it starts displaying the images, it comes up with a box asking me to choose the file from those listed on my desktop. Do you know how I can eliminate that part of the process?

SparkOut
Posts: 2947
Joined: Sun Sep 23, 2007 4:58 pm

Post by SparkOut » Wed Sep 09, 2009 9:17 am

You somehow have to let Rev know where to find the images to display. Mark's dialogue was just to make that easy for you to practice using the handler to display a random image from the collection at specified interval.
If you know for certain that the images will always be in a particular folder then you can script that line directly, as in

Code: Select all

set the default folder to "<the fixed path where the images are kept>"
but if you install on different machines you might have a problem where the installation on some machines is not in the same place as other machines. You could use relative file paths to make sure that the folder where the images are kept is always a subdirectory of the one where the application is executed. You need to look up in the docs (the Revolution dictionary) for defaultFolder and read about the way to reference file paths.

Post Reply