How to recall objects inside a group

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: Klaus, FourthWorld, heatherlaine, robinmiller, kevinmiller

Post Reply
ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

How to recall objects inside a group

Post by ale870 » Fri Jan 22, 2010 11:01 am

Hello,
I found a problem and I cannot find "the definitive solution".

This is the problem:
I created a group, called "g1", with two buttons inside, called "b1" and "b2":

Code: Select all

GROUP1
  |
  +--b1
  +--b2
Now when I push "b1" it call the handler "whoAreYou" in button "b2".
CODE FOR B1:

Code: Select all

send "whoAreYou" to button "b2"
CODE FOR B2:

Code: Select all

on whoAreYou
answer "I am b2-group 1"
end whoAreYou
Everything works perfectly.

Now, I duplicate this group (group "g1"), and in the same stack, I create this new copy called "g2". I simply change the code inside button "b2" to show the text: I am b2-group 2 <-- please note "group 2"
I do not change anything else, and I try to push button "b1" inside the new group "g2": SURPRISE! I get an answer from button "b2" inside group "g1"!!!!

I have some alternatives in my mind to solve this problem, but I don't like it. My purpose is creating a group where the objects inside refer only to other objects inside the group-self (even if another group with the same button name exists).
If I use card or stacks there are two wonderful properties called "this card" and "this stack": they refer to the object container. I think I need another property like "this group":

Code: Select all

send "whoAreYou" to button "b2" of this group -- DOES NOT WORK!

Code: Select all

answer "I am b2-" && the name of this group -- DOES NOT WORK!
Can you tell me how can I do this? Is it possible?

(I think this is the best approach to realize a "full object-oriented" RunRev architecture).

Thank you for your help!
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to recall objects inside a group

Post by ale870 » Fri Jan 22, 2010 11:28 am

EDIT: Now I solved creating this function and putting it in the stack containing the groups, but I hope a better (faster) solution could be found:

Code: Select all

function thisGroup
   local ret
   
   get wordOffset("group", the long name of target)
   if it is not empty then
      put word it to it+2 of the long name of target into ret
   else
      put empty into ret
   end if
      
   return ret
end thisGroup
Based on the previous example, in button "b1" now I can write:

Code: Select all

send "whoAreYou" to button "b2" of thisGroup()
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

ale870
Posts: 250
Joined: Tue Apr 22, 2008 9:17 am
Contact:

Re: How to recall objects inside a group

Post by ale870 » Fri Jan 22, 2010 11:35 am

Hello again, I found another alternative: it is faster (less code) but it must be located in every group (or inside a behavior attached to every group):

Code: Select all

function thisGroup
   return me
end thisGroup
It is trivial, but it works perfectly.
Runtime Revolution Widgets, tutorials, tips & tricks and more!
http://runrevwidgets.com/wiki

sturgis
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1682
Joined: Sat Feb 28, 2009 11:49 pm

Re: How to recall objects inside a group

Post by sturgis » Fri Jan 22, 2010 3:57 pm

You could also have done this to use your original method.

Code: Select all

    send "whoAreYou" to button "b2" of the owner of me
The owner of the button clicked is the group its in, so that defines where to look for button "b2".
Otherwise since you have 2 groups, and group 1 and group 2 have different object id's. when send is looking for the apropos button it finds whichever comes first in the message path. \

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”