Page 1 of 1

Storing Images for later use within the program

Posted: Thu Jun 27, 2013 7:56 pm
by JeffO2013
Hi,

I'm working on a project where I need the ability to select images and store them for use later. I have the code in place to select the images and store them in a variable. I can then have the image display in an image area on the same card as the button used to select it.

The problem I have is when I try to display the image (stored in a variable) in an image area on a different card in the stack

The code I'm using in the button is as follows

Code: Select all

on mouseUp
   answer file ""
   put it into targetArray
   
   if there is a file targetArray then
      put targetArray into field "Field"
      set filename of img "Image 2" to targetArray
   end if 
   
end mouseUp
and the image displays perfectly in "Image 2"

however, when I try to have the image display on the next card in an image area nothing happens. The code, which is on the card script, is as follows:

Code: Select all

on openCard
   set the filename of img "Image" to targetArray
end openCard
Also, I'll eventually have multiple images that will need to be displayed within image areas and these images will have to change using randomization and was going to store them in an array to make working with the code easier. I just need to get the image displaying properly for now so I will worry about that later.

any help anyone can offer would be greatly appreciated.

Re: Storing Images for later use within the program

Posted: Thu Jun 27, 2013 8:15 pm
by jmburnod
Hi Jeff,


targetArray is empty at the end of script.
You have to store the file path in a global variable or a custom property

With a custom property

Code: Select all

on mouseUp
   answer file " "
   put it into targetArray
   set the uMyCurImg of this stack to targetArray
   -- if there is a file targetArray then -- if you can select a file in a dialog box, it exists.
   put targetArray into field "Field"
   set filename of img "Image 2" to targetArray
   -- end if 
end mouseUp

on openCard
  -- set the filename of img "Image" to targetArray
   set the filename of img "Image" to the uMyCurImg of this stack to targetArray
end openCard
kind regards

Jean-Marc

Re: Storing Images for later use within the program

Posted: Fri Jun 28, 2013 1:07 am
by JeffO2013
Thank you Jean-Marc, but targetArray was a global variable declared on the mainstack script. I tried moving it to the button script (inside the mouseUp command) but still no luck.

Any other suggestions?

I hesitate to use a custom property because I will eventually have to handle multiple images and display them on the screen and I'm not sure how that would work for multiple images. As is, I was going to try and use an array to store the images as I'll have two sets (targets and distractors) and felt this would make it easier to store and track the two.

Re: Storing Images for later use within the program

Posted: Fri Jun 28, 2013 10:30 am
by jmburnod
Hi Jeff,

You have to declare your global in a front of each script uses it
With a global

Code: Select all

btn script
global gTargetArray
on mouseUp
   answer file " "
   put it into gTargetArray
   put gTargetArray into field "Field"
   set filename of img "Image 2" to gTargetArray
end mouseUp

stack script
global gTargetArray
on openCard
 set the filename of img "Image" to gTargetArray
end openCard
kind regards

Jean-Marc

Re: Storing Images for later use within the program

Posted: Sat Jun 29, 2013 2:35 am
by JeffO2013
Thank you, Jean-Marc,

That fixed it. I imagined it was something simple I was overlooking.

Again, Thanks for your help!