Page 1 of 1

How do I erase graphics?

Posted: Thu Jun 14, 2007 3:54 pm
by Arndt
Hello folks,

I am excited about Revolution Studio, and now I imported an old HyperCard stack for the first time.
Almost everything works fine (and I can fix the remaining problems), but after trying some time with different functions and searching the help engine, I gave up with this problem:

I want to erase all graphic objects (lines etc.) on a specific card automatically. In the Hypercard version, I used this handler:

on clearscreen
choose "select tool"
doMenu "Select all"
doMenu "Clear Picture"
end clearscreen

This doesn't work, even when I translate it to the syntax of RR.
There MUST be a solution. Does anybody know it?

Thanks a lot,

Arndt

Posted: Thu Jun 14, 2007 9:44 pm
by xApple
In the stack script:

Code: Select all

getProp objects 
  repeat with x = 1 to number of controls of the target 
    put the long name of control x of the target & return after myList 
  end repeat 
  sort myList 
  return myList 
end objects 
Anywhere:

Code: Select all

on deleteAllObjOfCd cardNum
 put the objects of card cardNum into cardObjects 
  repeat for each line curObj in cardObjects
    delete  curObj
  end repeat
end deleteAllObjOfCd

???

Posted: Fri Jun 15, 2007 9:58 am
by Arndt
Dear xApple....

... sorry, but I am probably too stupid to understand your code and how to use it.
Do you have some explanations for me or even a simpler (more "intuitive") way for doing it?

Sorry for being a dummie,
Arndt

Posted: Fri Jun 15, 2007 2:26 pm
by BvG
Here's a maybe simpler to understand example (with bonus comments):

Code: Select all

on mouseUp
  --will run if you click on button containing the script
  lock screen
  --makes it run faster, remove for visual proofing
  put the number of graphics into theGraphsCount
  repeat with currentGraphic = theGraphsCount down to 1
    --will loop as many times as there are graphics
    if there is a graphic currentGraphic then
      --check if there really is a graphic currentGraphic (optional)
      delete graphic currentGraphic
      --removes the graphic
    end if
  end repeat
end mouseUp
--the 3 lines above end all the opened control structures
When I started beginning using loops to delete objects, I always tried to use "repeat for the number of graphics times". But that wouldn't work, and I had to make complicated workarounds. That is because it would delete a graphic, and that'd change the number of graphics. So after deleting half of them, it would try to delete non-existent graphics, and generate an error. The above example should work fine though, because it starts deleting at the top, and automatically subtracts one from the variable "currentCount".

Re: How do I erase graphics?

Posted: Mon Jul 09, 2012 10:28 pm
by jlally
Hello,

I'm wondering if there's an easy way to select (and ultimately delete) multiple buttons on a card by name? I'm not looking to delete *all* of the buttons on my card, just the ones that begin with "myButtonNamePrefix". I'm relatively new to LiveCode, and in other scripting languages, I'd just do something like this (using a "*" wildcard):

select "myButtonNamePrefix*"
delete selected

or more simply:

delete "myButtonNamePrefix*"

Any help would be greatly appreciated!

Thanks in advance,
John

Re: How do I erase graphics?

Posted: Mon Jul 09, 2012 10:38 pm
by mwieder
John-

you'll have to resort to a repeat loop for this:

Code: Select all

put the number of buttons of this card into tCount
repeat with x=tCount down to 1
  if the short name of button x of this card begins with "myButtonNamePrefix" then
    delete button x of this card
  end if
end repeat

Re: How do I erase graphics?

Posted: Mon Jul 09, 2012 10:55 pm
by jlally
Cool - looks like that's going to work! :D

Thanks so much, mwieder!