Handler for object created dynamically

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
michel_bujardet
Posts: 45
Joined: Mon Apr 21, 2014 10:41 am
Contact:

Handler for object created dynamically

Post by michel_bujardet » Fri May 02, 2014 6:56 pm

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.

Mitch
http://FontMenu.com

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Handler for object created dynamically

Post by Simon » Fri May 02, 2014 7:59 pm

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)
I used to be a newbie but then I learned how to spell teh correctly and now I'm a noob!

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Handler for object created dynamically

Post by Dixie » Fri May 02, 2014 8:09 pm

To try this out... put this into a button on a card.. then 'click' it...:-)
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
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

Simon
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3901
Joined: Sat Mar 24, 2007 2:54 am

Re: Handler for object created dynamically

Post by Simon » Fri May 02, 2014 9:05 pm

Hi Dixie,
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!

michel_bujardet
Posts: 45
Joined: Mon Apr 21, 2014 10:41 am
Contact:

Re: Handler for object created dynamically

Post by michel_bujardet » Fri May 02, 2014 11:01 pm

Dixie 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
Dixie, I applied this and it worked like a charm. Thank you so much for sharing your terrific knowledge :)

Mitch
http://FontMenu.com

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Handler for object created dynamically

Post by FourthWorld » Fri May 02, 2014 11:05 pm

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

FourthWorld
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10052
Joined: Sat Apr 08, 2006 7:05 am
Contact:

Re: Handler for object created dynamically

Post by FourthWorld » Sat May 03, 2014 1:25 am

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
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Handler for object created dynamically

Post by Dixie » Sat May 03, 2014 8:59 am

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...:-)
Hi 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.
Dixie

michel_bujardet
Posts: 45
Joined: Mon Apr 21, 2014 10:41 am
Contact:

Re: Handler for object created dynamically

Post by michel_bujardet » Sat May 03, 2014 9:00 am

FourthWorld 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
Thank you for the copy command :)

Mitch
http://FontMenu.com

Post Reply