1

In Hypercard I can store pictures only on cards. In LiveCode it is possible to store a collection of pictures on the stack level. Is this correct? If yes, how do I load all the pictures in a folder into a stack? And how do I change the read script to only read all the references to pictures into the stack?

z--
  • 2,186
  • 17
  • 33

3 Answers3

3

I think it's not possible to store images in a stack, but not on a card. For storing images on a card, you'll want the import command. It will place an image on the current (frontmost) card, for example:

answer file "select a picture"
if it <> "" then
   import paint from file it
end if

To import several images from one folder, you can use the ask folder command, and use the defaultfoder and the files to get them all:

answer folder "select a folder"
if it <> "" then
   set the defaultfolder to it
   put the files into myListOfFiles
   repeat for each line myFile in myListOfFiles
      import paint from file myFile
   end repeat
end if

Note that some OSes have hidden files that will show up in the files. To avoid them, you need to filter them out, for example on Mac OS X:

filter myListOfFiles without ".*"

Another way to avoid unwanted filetypes is to add a qualifier for files you want to include:

if char -4 to -1 of myFile is among the items of ".gif,.jpg,jpeg,.png,.bmp,.tif,tiff" then
   import paint from file myFile
end if
BvG
  • 425
  • 3
  • 3
3

It's not too hard to store images in a stack without placing them on a card. Do this:

Create a group on any card. Import all your images into it. In the Object menu, choose "Remove group".

This removes the group from the card but does not delete it. The group of images exists on no card but all your images are available. You can reference them normally, use them as icons, copy them to a card later, whatever you need. It's like having an invisible group on a card, only it isn't an object in the hierarchy. It receives no messages and isn't in the object layering.

This is how imported HyperCard stacks store their icon images, by the way. After an HC import you can find an unplaced group named "HC Icons" in the "Place group" menu item in the Object menu. It doesn't exist on any card, but all the imported buttons still show their icons.

Jacque
  • 416
  • 2
  • 7
1

You could store all the images in a folder in a stack with something like;

answer folder "Select the folder containing your images"
if it <> "" then
  set the folder to it
  put the files into tFiles
  repeat for each line tFile in tFiles
    set the uImages[tFile] of this stack to URL("binfile:" & tFile)
  end repeat
end if

If you had an image object on your card called 'myImage', and one of the images in the folder was called 'car.png', you could then;

set the text of image "myImage" to the uImages["car.png"] of this stack

To retrieve the list of images stored in the stack, you can reference;

put the customKeys["uImages"] of this stack into tImageList

HTH :)

splash21
  • 799
  • 4
  • 10
  • `uImages` is an array containing file references? I do not see where the variable `tImageList` is defined. – z-- Apr 29 '13 at 16:45
  • uImages is a custom property set (an array of custom properties) created in the repeat loop. tImageList can be any variable - I just created it by dumping the keys of the property set in it. Check out section 7.9 of the LiveCode user guide for more info on custom property sets. – splash21 Apr 29 '13 at 21:39
  • In 7.8.3 **The Content of a Custom Property** I found: *You set the value of a custom property by using its property name together with the set command, in the same way you set built-in properties* – z-- May 01 '13 at 22:39
  • Section 7.9.8 : Arrays, custom properties, and custom property sets – splash21 May 02 '13 at 09:36