How can a button remove itself from a card?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
How can a button remove itself from a card?
I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
The remove button takes the item out of an items array, removes the corresponding field from the card.
Finally of course it should dispose of itself.
This naturally fails with an (Object: stack locked, of object's script is executing) - as the button holds the self destruction order.
Is there a way to acomplish self-destruction other than going to another card and put the cleanup of the list into the preopencard when it is opened the next time?
The remove button takes the item out of an items array, removes the corresponding field from the card.
Finally of course it should dispose of itself.
This naturally fails with an (Object: stack locked, of object's script is executing) - as the button holds the self destruction order.
Is there a way to acomplish self-destruction other than going to another card and put the cleanup of the list into the preopencard when it is opened the next time?
Re: How can a button remove itself from a card?
Put a handler in the stack to remove the button then use "send" to call that handler.
-
- Posts: 192
- Joined: Tue Mar 11, 2014 12:57 pm
Re: How can a button remove itself from a card?
Do you have a clever way to dynamically position objects for any device - tablet etc?Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
?
I'm still waiting to figure out how to get fullscreenmode "exactfit" etc to work with a scrolling group of objects any phone/tablet size landscape/portrait.
I did experiment using screenrect and then changing the width, height factor of this rect to calc the scroller contentrect for either landscape or portrait.
or set the scaleFactor of stack "Stack" to ... but I didn't resolve it.
Last edited by newtronsols on Fri Nov 21, 2014 5:12 pm, edited 1 time in total.
-
- Posts: 192
- Joined: Tue Mar 11, 2014 12:57 pm
Re: How can a button remove itself from a card?
Do you have a clever way to dynamically position objects for any device - tablet etc?Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
?
I'm still waiting to figure out how to get fullscreenmode "exactfit" etc to work with a scrolling group of objects any phone/tablet size landscape/portrait.
I did experiment using screenrect and then changing the width, height factor of this rect to calc the scroller contentrect for either landscape or portrait.
or set the scaleFactor of stack "Stack" to ... but I didn't resolve it.
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How can a button remove itself from a card?
If the button will ever be needed again in the future beyond that one use, why not just hide it?Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
The remove button takes the item out of an items array, removes the corresponding field from the card.
Finally of course it should dispose of itself.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: How can a button remove itself from a card?
This List is a set of "Favourites" without Limitation, so a user can have between no and an "unlimited" number of Entries.FourthWorld wrote:If the button will ever be needed again in the future beyond that one use, why not just hide it?Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
The remove button takes the item out of an items array, removes the corresponding field from the card.
Finally of course it should dispose of itself.
I had a first version with the hide and show approach, but handling of this just looks easier to me when I create and remove the items instead of keeping control over a set of un/-visible objects.
Re: How can a button remove itself from a card?
I don't know if that's clever but it mostly works:newtronsols wrote:Do you have a clever way to dynamically position objects for any device - tablet etc?Havanna wrote:I have a List of info-fields, each with a button to remove this entry, all created dynamically by script.
?
I use a handler to determine all relevant layout values and put them into a global array, so I can acces that from anywhere.
This handler is called on startup (and resize)
I set FontSizes and Layout margins and button sizes from here
Position of Objects i find reasonably simple by making "Object type Handlers" like: SetButton ButtonID, tButtonType, tButtonColor, tTextColor
in there I calculate the details from global button size, global button spacing and so on. Also a global "Left" and "Top" value make for a sort of Layout cursor, that gets updated in every "Object Type Handler"
Works quite nicely, but is a lot of codewriting of course, with the benefit of full layout control.
For different platforms and orientations, differend layout basics handlers do the job for me.
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: How can a button remove itself from a card?
on mouseUp
delete button "XX"
end mouseUp
dead easy
delete button "XX"
end mouseUp
dead easy
-
- Livecode Opensource Backer
- Posts: 10099
- Joined: Fri Feb 19, 2010 10:17 am
Re: How can a button remove itself from a card?
mind you a button CANNOT delete itself
Re: How can a button remove itself from a card?
Hi Havanna,
make a button
the button is gone.
Of course you put similar code into your self-destruction handler.
Kind regards
Bernd
make a button
Code: Select all
on mouseUp
put the long id of me into tLID
send "delete tLID" to this card in 5 milliseconds
end mouseUp
Of course you put similar code into your self-destruction handler.
Kind regards
Bernd
Re: How can a button remove itself from a card?
You can also put
into the script of the button. The button is gone after mouseUp
The main reason an object can not delete itself is that the code to delete is still running. With "send in time" the code is not running anymore and deletion can happen.
Kind regards
Bernd
Code: Select all
on mouseUp
put the long id of me into tLID
send "delete tLID" to me in 5 milliseconds
end mouseUp
The main reason an object can not delete itself is that the code to delete is still running. With "send in time" the code is not running anymore and deletion can happen.
Kind regards
Bernd
Re: How can a button remove itself from a card?
Bernd, that is a very interesting situation, I wouldn't have expected time to make a difference. Instead I thought deleting an object would only be possible from the outside thanks a lot.bn wrote: The main reason an object can not delete itself is that the code to delete is still running. With "send in time" the code is not running anymore and deletion can happen.
Andreas
-
- VIP Livecode Opensource Backer
- Posts: 10049
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: How can a button remove itself from a card?
Your expectation is spot-on: the "delete" command is being handled by the engine, and with the delay in sending it occurs after the button's own script has completed. So at that point, the actual deletion is being handled outside the button script.Havanna wrote:I wouldn't have expected time to make a difference. Instead I thought deleting an object would only be possible from the outside thanks a lot.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn