• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: set parent
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: set parent


  • Subject: Re: set parent
  • From: has <email@hidden>
  • Date: Tue, 6 Aug 2002 14:33:02 +0100

Seth Roby wrote:

>I am getting an error that I can't set parent to <<script>>, and I think
>that that's rather odd.
>
>The situation is as follows:
>
>foo.scpt----------------------------------------
>property child : ""
>
>on run
> set child to load script file "disk:folder:bar.scpt"
> tell child to init(me)
>end run
>
>bar.scpt--------------------------------------
>on init(owner)
> set parent to owner
>end init
>
>
>But when I run, I get an error that I "Can't set parent to <<script>>". I
>thought that setting parents to scripts was the whole point; obviously, I'm
>missing something or setting this up wrong.


Alas, you can only set an object's parent when you create it. You cannot
change it once the object exists. Still, consider yourself fortunate you're
not stuck on some boring old traditional class-based language where
inheritance is set in stone at compile-time. At least with AS you have some
degree of flexibility at runtime.

One solution to your problem would be to use a constructor function in
bar.scpt:

-------
--bar.scpt

on newBar(theParent)
script
property parent : theParent

--rest of bar's code here
end script
end newBar

-------

-------
--foo.scpt

property child : ""

on run
set child to newBar(me) of load script (file "disk:folder:bar.scpt")
end run

-------

Though what this is intended for I'm not entirely clear - want to enlighten?

HTH

has



--
(My email address has changed from <email@hidden> to
<email@hidden>. Please update your address books accordingly.)
_______________________________________________
applescript-users mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/applescript-users
Do not post admin requests to the list. They will be ignored.

  • Prev by Date: Re: is this a bug?
  • Next by Date: Re: Sending EMails with Attachment
  • Previous by thread: Re: set parent
  • Next by thread: Re: set parent
  • Index(es):
    • Date
    • Thread