[Sorry if this is a duplicate, having trouble with mail]

(It's amazing how much time can be wasted when one's Internet Service 
Provider goes out of business and you have to switch to another one - 
especially with a DSL line, and even more so if you have your own 
domain name, but I digress ...)

The basic approach that I would take would be to create a single 
"object manager object".  That is, if you want to create a bunch of 
Widget (objects), then have a WidgetMgr object who is responsible for 
maintaining the list.

 From your sample code, I don't understand the relationship as far as 
what is a parent script and what is a behavior.  I also don't have a 
clue as to what you want each of these objects to do - that is, what 
are the object's  handlers - basically what should the objects be 
able to do.  Do you need to "address" individual objects, or would 
you be broadcasting messages to all at the same time.

Anyway, here's a snippet of an approach (untested).  The Widget 
object manager is responsible for creating any and all Widget 
objects, and internally, it does this by maintaining a list of object 
references to all Widget objects that it has created.

-- WidgetMgr parent script

property ploWidgets  -- property which is a list of object references 
to Widget objects

on new me
   ploWidgets = []
   return me
end

on mCreateNewWidget me, [any parameters you might want to pass when 
you create a Widget]
   -- First create the widget object
   oWidget = new(script "Widget",  [any parameters you might want to 
pass when you create a Widget])
   -- Next, add this object reference to the list
   append(ploWidgets, oWidget)

    -- If the "thing" that asked to create the object needs the object 
reference back,
    -- return it,  if not, don't return anything
    return oWidget
end

on mDoSomethingToAllWidgets me
   repeat with oWidget in ploWidgets
      oWidget.mDoSomething()
   end repeat
   -- The above could be done with a "call" statement if you wish
end

And the Widget script is very basic

on new me, [any parameters you might want to set ...]
    --  any initialization code
    return me
end

on mDoSomething me
   -- Whatever
end


The WidgetMgr probably needs to be a global, if you want it to hang 
around for a long time.  Something like this:

global goWidgetMgr  -- global object, Widget Manager

on startMovie
   goWidgetMgr = new(script "WidgetMgr")
end

on stopMovie
   goWidgetMgr.mCleanUp()  -- give the WidgetMgr a chance to clean itself up
   goWidgetMgr = VOID  -- throw away the instance variable
end

.. then the WidgetMgr needs a cleanup handler, something like this:

on mCleanUp me
   nWidgets = count(ploWidgets)
   repeat with i = 1 to nWidgets
      oWidget = ploWidgets[i]
      oWidget.mCleanUp()  -- allow each widget to clean itself up
      ploWidgets[i] = VOID
   end repeat
end

And the Widget script needs to have:

on mCleanUp me
     -- clean up any objects that it may have created
end

If this doesn't make much sense, you can read more at:

   http://www.furrypants.com/loope

Irv

PS:  Using "data cast members" for this type of storage is not the 
right thing to do since object references are really memory 
addresses, and are subject to change each time you run your program.


-- 

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!]

Reply via email to