Centering an object in a window

Monte Goulding monte at sweattechnologies.com
Mon Aug 11 21:19:01 EDT 2003


>
> I'm not sure if this is the proper method but it worked so I thought
> I'd post it.
>
> on centerTheObject
>    global theObject
>    set the loc of theObject to (item 1 of the localloc of the loc of
> this stack) ,\
> 	(item 2 of the localloc of the loc of this stack)
> end centerTheObject
>
> In the script that calls the above, I use:
>
> put myObject into theObject
> -- "myObject" for example being "field m144" (using quotes)
>
> Hope this helps someone.
>

Hey Barry

That seems to work but you can also use the loc of the card to get the same
result.

Over on the improve list there is a discussion on using setProp handlers to
improve the syntax of things like this. To do that you could have a setProp
handler such as:

/**
this wouldn't do quite the same (it would also center grouped objects
relative to the group rather than card)
*/

setProp centered pBoolean
  if pBoolean then
    set the loc of the target to the loc of the owner of the target
  end if
end centered

Then you can do the following:

set the centred of me to true

or

set the centred of btn 1 to true

Cheers

Monte




More information about the use-livecode mailing list