Re: Error Number: -10006 H-E-L-L-L-P!
Re: Error Number: -10006 H-E-L-L-L-P!
- Subject: Re: Error Number: -10006 H-E-L-L-L-P!
- From: Michael Terry <email@hidden>
- Date: Fri, 23 Jan 2004 01:10:35 -0800
On Jan 22, 2004, at 10:55 AM, Wallace, William wrote:
--main script
property z : 3
global w, x, y
property dPath : (path to desktop) as string
set m to (load script alias (dPath & "script1"))
set p to (load script alias (dPath & "script2"))
set r to (load script alias (dPath & "script3"))
set x to "hi"
set y to {"yesterday"}
r's prepareIt(y)
p's suggestIt()
display dialog (z as string) --> 4
display dialog x --> howyadoin
display dialog w --> w is undefined
--loaded script1
to doIt()
try
set my parent's z to 4
set my parent's x to "howyadoin"
set my parent's w to (item 1 of my parent's y)
on error errMsg number errNum
display dialog "Error! " & errNum & return & errMsg
end try
end doIt
--loaded script2
to suggestIt()
tell my parent's m to doIt()
end suggestIt
--loaded script3
to prepareIt(theDingus)
set item 1 of theDingus to current date
end prepareIt
What I don't understand is why script1 throws a -10006 error
(errAEWriteDenied) when trying to set the value of w to item 1 of y.
The dialog boxes at the end of the main script show that the value of
z has been changed to 4, the value of x has been changed to
"howyadoin", but w is, of course, undefined because of the error
-10006. Why can't script1 set the value of w? Furthermore, If I change
the main script to initialize the value of w to "today" for instance,
it all works. Why?
Do these loaded scripts have parent property declarations in them
somewhere? I don't see them here, but you refer to the calling script
as if you had. I assume you must have, else your main script should be
getting lots of errors. Unless otherwise specified, the parent script
of a loaded script is <<script AppleScript>>.
Anyway, I don't know if there's a better explanation than that it just
doesn't work. Children are bound to their parents statically; they can
only see globals that were already initialized by the parent at binding
time. This means properties obviously--which are set at compile time or
when a script is created through a constructor function--and any
globals that have already had their values set when the script became
another script's parent.
For instance:
script a
global x
on init()
set x to 1
me
end init
end script
script b
property parent : a
parent's init()
parent's x
end script
run script b
--> error
Even though we tried to initialize x by calling init(), it doesn't
matter because the globals visible to script b were set when script a
was compiled in as b's parent. Now, instead we do this:
script a
global x
on init()
set x to 1
me
end init
end script
script b
property parent : a's init()
parent's x
end script
run script b
--> 1
and everything is hunky dory. I don't know why children have this
somewhat standoffish relationship with their parents. Even unrelated
scripts can access calling scripts' globals with ease, if we amend your
examples:
-------------------------------------------
-- Calling script
-------------------------------------------
property z : 3
global w, x, y
property dPath : (path to desktop) as string
set m to (load script alias (dPath & "script1"))
set p to (load script alias (dPath & "script2"))
set r to (load script alias (dPath & "script3"))
set x to "hi"
set y to {"yesterday"}
r's prepareIt(y)
p's suggestIt()
display dialog (z as string)
display dialog x
display dialog w as item as string
-------------------------------------------
-- script1
-------------------------------------------
to doIt()
global z, x, w, y
try
set z to 4
set x to "howyadoin"
set w to (item 1 of y)
on error errMsg number errNum
display dialog "Error! " & errNum & return & errMsg
end try
end doIt
-------------------------------------------
-- script2
-------------------------------------------
to suggestIt()
global m
tell m to doIt()
end suggestIt
-------------------------------------------
-- script3
-------------------------------------------
to prepareIt(theDingus)
set item 1 of theDingus to current date
end prepareIt
There's nothing stopping children from doing this, too.
Mike
_______________________________________________
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.