I made a button with the intention that it will reset the page or delete all of the buttons that were created by the user.
the following works for deleting one button:
on mouseUp
delete button "mybutton1"
end mouseUp
the following also seems to work:
on mouseUp
delete button "mybutton1" and button "mybutton2"
end mouseUp
However, if I have more than one "mybutton1" on the page it will only delete the last one created and not all of them and if one of the buttons listed in that code an error occurs because it doesn't exist.
Delete more than one button
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Re: Delete more than one button
Hi.
Fun stuff. But you must be patient. Learning LiveCode requires effort, commitment and time. The good news it is easy and enjoyable to become fairly proficient, usually in only a couple of months.
I am always learning. I had no idea that:
was even possible.I would have bet it would throw a runtime error. I am going to update the "delete" entry in the dictionary.
Anyone else surprised as I was???
Anyway. There are several ways to refer to controls. You already know about names. There are others, and these may be more suited to your task. But even names can be used, if you form your buttons in a way that lends itself to such a method. Say you did this:
Now you have to be careful if the button with this handler in it is also named "myButtonWhatever". Check out that old "delete" entry in the dictionary to see why. Makes sense, though, eh?
The seeds of some other methods are in the above handler. Foe example, what if you simply just deleted button y? Then the name would not matter at all. But, again, watch out for that little wrinkle I mentioned. Can you think of other ways?
Write back. There is much to get to know...
Craig Newman
Fun stuff. But you must be patient. Learning LiveCode requires effort, commitment and time. The good news it is easy and enjoyable to become fairly proficient, usually in only a couple of months.
I am always learning. I had no idea that:
Code: Select all
delete button "mybutton1" and button "mybutton2"
Anyone else surprised as I was???
Anyway. There are several ways to refer to controls. You already know about names. There are others, and these may be more suited to your task. But even names can be used, if you form your buttons in a way that lends itself to such a method. Say you did this:
Code: Select all
on mouseUp
repeat with y + 1 to the number of buttons
if the name of button y contains "myBotton" then delete button y
end repeat
end mouseUp
The seeds of some other methods are in the above handler. Foe example, what if you simply just deleted button y? Then the name would not matter at all. But, again, watch out for that little wrinkle I mentioned. Can you think of other ways?
Write back. There is much to get to know...
Craig Newman
Re: Delete more than one button
Surprised? Yes!
This is as odd as the "repeat with 1 = 1 to 9" thing.
This is as odd as the "repeat with 1 = 1 to 9" thing.
Re: Delete more than one button
And pssst, Craig... I will just mention "down to"