reset/ delete image if exist then create new image

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
reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

reset/ delete image if exist then create new image

Post by reelstuff » Thu Aug 16, 2007 12:40 am

Hi, I have a button I want to use to reset to a new image.

So if there is an image there I want to delete that image and
create new blank image and position it.

I tried several variations and get different errors, for me its usually in the syntax.
err
Chunk: no such object
Object Button
Line if exist (image "iData")
Hint iData

Code: Select all

on mouseUp
  if exist (image iData) then
  delete "iData"
  new image "iData"
 end if
end mouseUp
I know I am missing something, but at the moment it escapes me,

once I get this to work I can then go on to positioning the new image to a certain spot on the screen.

thanks for any suggestions.

Tim

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

Post by Klaus » Thu Aug 16, 2007 8:38 am

Hi reelstuff,

yep, there is missing something in your script:

Code: Select all

on mouseUp 
  if existS (image iData) then 
  delete IMAGE "iData" 
  CREATE image "iData" 
 end if 
end mouseUp 
BUT it is not necessary to delete the old image, you can simply empty it!
That's a lot cheaper than buying a new one ;-)

Code: Select all

on mouseUp 
  if existS (image iData) then 
   put empty into image "iData" 
  end if 
end mouseUp 

Best

Klaus

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

Post by reelstuff » Thu Aug 16, 2007 12:38 pm

Thank you Klaus, that is excellent, I believe I am beginning to see a little better now, that was very helpful.

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

Post by Klaus » Thu Aug 16, 2007 12:43 pm

Hi reelstuff,

glad I could help :-)

Hint:
This will of course only work with imported images.
If you are working with referenced images you can simply:

...
set the filename of img "iData" to empty
...


Best from germany

Klaus

reelstuff
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 254
Joined: Mon Apr 16, 2007 12:06 am
Contact:

Post by reelstuff » Thu Aug 16, 2007 5:32 pm

Even Better, thank you
Klaus wrote:Hi reelstuff,

glad I could help :-)

Hint:
This will of course only work with imported images.
If you are working with referenced images you can simply:

...
set the filename of img "iData" to empty
...


Best from germany

Klaus

Post Reply