Handler for object created dynamically
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
- Posts: 45
- Joined: Mon Apr 21, 2014 10:41 am
- Contact:
Handler for object created dynamically
With a control placed on a card at design time, I simply go to the script for that control, but a dynamically created object does not exist at design time.
When I create a field dynamically, if the user clicks on that field, how and where can I create a handler for the mouseDown event for that object ?
Is that possible ?
Thanks.
When I create a field dynamically, if the user clicks on that field, how and where can I create a handler for the mouseDown event for that object ?
Is that possible ?
Thanks.
Mitch
http://FontMenu.com
Re: Handler for object created dynamically
Hi Mich,
In this case you would use "target" and the mouseUp/down handler would be in the stack/card/group script.
on mouseUp
answer the target
end mouseUp
Simon (err one persons opinion)
In this case you would use "target" and the mouseUp/down handler would be in the stack/card/group script.
on mouseUp
answer the target
end mouseUp
Simon (err one persons opinion)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
Re: Handler for object created dynamically
To try this out... put this into a button on a card.. then 'click' it...
Read up on 'template' in the Dictionary...
or maybe something as simple as...

Read up on 'template' in the Dictionary...
Code: Select all
on mouseUp
set the width of the templatefield to 200
set the height of the templatefield to 30
set the textfont of the templatefield to "helvetica"
set the textsize of the templatefield to 18
set the loc of the templatefield to the loc of this card
set the name of the templatefield to "myNewField"
set the text of the templatefield to "'Click' me"
set the lockText of the templatefield to true
set the lockLoc of the templatefield to true
put "on mouseDown" & cr & "beep" & cr & "end mouseDown" into theScript
set the script of the templatefield to theScript
create field
end mouseUp
Code: Select all
put "on mouseDown" & cr & "beep" & cr & "end mouseDown" into theScript
set the script of button X of this card to theScript
Re: Handler for object created dynamically
Hi Dixie,
Is it true that scriptLimits have been removed?
Simon
Is it true that scriptLimits have been removed?
Simon
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!
-
- Posts: 45
- Joined: Mon Apr 21, 2014 10:41 am
- Contact:
Re: Handler for object created dynamically
Dixie, I applied this and it worked like a charm. Thank you so much for sharing your terrific knowledgeDixie wrote:To try this out... put this into a button on a card.. then 'click' it...
Read up on 'template' in the Dictionary...
or maybe something as simple as...Code: Select all
put "on mouseDown" & cr & "beep" & cr & "end mouseDown" into theScript set the script of button X of this card to theScript

Mitch
http://FontMenu.com
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Handler for object created dynamically
A bug had prevented scriptLimits from working in some recent versions; this is planned for correction in v6.7:
http://quality.runrev.com/show_bug.cgi?id=11797
http://quality.runrev.com/show_bug.cgi?id=11797
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
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Handler for object created dynamically
One of the problems with LiveCode is that there are too many ways to do nearly everything, and all of them are fun to explore. 
Another solution for this is to use behaviors: define the behavior for the newly-created fields in a separate object, and set the new field's behavior property to that object.
And if you prefer to create your template field graphically rather than in script, you could store one set up as you like it and use the copy command so you'll get your new field in one line:

Another solution for this is to use behaviors: define the behavior for the newly-created fields in a separate object, and set the new field's behavior property to that object.
And if you prefer to create your template field graphically rather than in script, you could store one set up as you like it and use the copy command so you'll get your new field in one line:
Code: Select all
copy field "MyTemplateField" of stack "MyAppResources" to this card of the topstack
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: Handler for object created dynamically
Simon...
I thought that script limits had been removed... it seems there are no script limits in 'community' but there are in 'commercial'. below is a note to Ben Rubenstein from Mark Waddingham in the Quality Control Centre... Who knows which way it will pan out...
I thought that script limits had been removed... it seems there are no script limits in 'community' but there are in 'commercial'. below is a note to Ben Rubenstein from Mark Waddingham in the Quality Control Centre... Who knows which way it will pan out...

DixieHi Ben,
The script limits were removed from community as they made no sense there - commercial was always intended to remain as it was.
We are currently reviewing the scriptlimits in commercial. In the meantime they are enforced in the 6.7+ engine.
Warmest Regards,
Mark.
-
- Posts: 45
- Joined: Mon Apr 21, 2014 10:41 am
- Contact:
Re: Handler for object created dynamically
Thank you for the copy commandFourthWorld wrote:One of the problems with LiveCode is that there are too many ways to do nearly everything, and all of them are fun to explore.
Another solution for this is to use behaviors: define the behavior for the newly-created fields in a separate object, and set the new field's behavior property to that object.
And if you prefer to create your template field graphically rather than in script, you could store one set up as you like it and use the copy command so you'll get your new field in one line:
Code: Select all
copy field "MyTemplateField" of stack "MyAppResources" to this card of the topstack

Mitch
http://FontMenu.com