Second question first. Simply add a "global" statement, e.g.,
global gSomeVariableName
The first letter of "g" is a common convention indicating that the
variable is a global. You need to include this line at the top of
every script where you want to use the variable.
To answer the second, here's what I would do. You don't say what
your objects are, so I'll make one up. Let's say that you want to
create a bunch of Foo objects from a Foo parent script. There are
two approaches:
1) Use a single global property list, where the property is the
name, and the value is the object reference. Something like this:
global gObjectList
on startMovie
gObjectList = [:]
addProp(gObjectList, "Chris", new(script "Foo"))
addProp(gObjectList, "Irv", new(script "Foo"))
...
addProp(gObjectList, "Tab", new(script "Foo"))
end
You wind up with a property list like this:
["Chris": object reference to a "Foo" object, "Irv": object
reference to a "Foo" object, ...
Then when you want to refer a particular object by name, you get the
object reference by find it by name in the global object list:
-- Let's send a message to the Irv object
oFoo = getAProp(gObjectList, "Irv")
oFoo.mSendSomeMessage()
2) Create a global linear list of Foo objects where each one has a
pName property. Then when you want to send a message to an object,
first find the appropriate one then send it a message:
global gObjectList
on startMovie
gObjectList = []
append(gObjectList, new(script "Foo", "Chris"))
append(gObjectList, new(script "Foo", "Irv"))
...
append(gObjectList, new(script "Foo", "Tab"))
end
on SendMessageToObject theTargetName, theMsg
repeat with oFoo in gObjectList
thisName = oFoo.mGetName()
if thisName = theTargetName then
oFoo.mSendSomeMEssage(theMsg)
exit repeat
end if
end repeat
end
You wind up with a property list like this:
[object reference to a "Foo" object,object reference to a "Foo" object, ...]
And the Foo object works like this:
property pName
on new me, theName
pName = theName
return me
end
on mGetName me
return pName
end
on mSomeMsg me, theMsg
-- do something with theMsg
end
I strongly prefer #2. I believe that the second approach is better
because the name should be a "property" of the object, rather than
having the name live outside the object in the property list.
Hope this helps,
Irv
At 4:46 PM -0700 4/25/01, Chris Daniels wrote:
>i'm a little embarassed to ask this because i feel that i should know it
>already... but here it goes...
>
>i want to create a child object from a parent script and be able to refer to
>it globaly using a string that i pass to it! i want to give all these
>children their own individual names and be able to call them individually!
>how on earth do i do that?
>
>a related question is.. how can i globalize variables?
>
--
Lingo / Director / Shockwave development for all occasions.
(Home-made Lingo cooked up fresh every day just for you.)
[To remove yourself from this list, or to change to digest mode, go to
http://www.penworks.com/LUJ/lingo-l.cgi To post messages to the list,
email [EMAIL PROTECTED] (Problems, email [EMAIL PROTECTED])
Lingo-L is for learning and helping with programming Lingo. Thanks!]