• 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: script object properties: seeking confirmation
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: script object properties: seeking confirmation


  • Subject: Re: script object properties: seeking confirmation
  • From: Arthur J Knapp <email@hidden>
  • Date: Tue, 05 Mar 2002 09:50:36 -0500

> Date: Mon, 04 Mar 2002 15:34:56 -0800
> From: Bill Hoffman <email@hidden>
> Subject: script object properties: seeking confirmation

> In a handler declared within an AppleScript script object, the handler
> can _not_ create new properties of an object by assigning values to an
> otherwise undeclared property

Correct. Like every other aspect of AppleScript, named-identifiers
cannot be created at run-time, ie: record properties, variable names,
etc.

> script myObject

> property occupation: ""

> on updateObj()
> set occupation to "janitor"
> set income to 500

> when I tell a myObject variable to updateObj(), the "set occupation to
> 'janitor'" statement is fine, but the "set income to 500' statement will
> fail with an error, telling me that there is no such property as
> "income".

Really ?

Income should be treated as a local variable, I can't imagine why
there would be an error.

> ... I can't dynamically create a new property of an object at
> runtime in this manner (like I could in JavaScript, for example, with
> "this.income = 500;")

JavaScript is a very dynamically constructed language. AppleScript
was desgined with a different set of principles.

> If there's a way to do that I'd love to know how, but I'm pretty sure
> there isn't.

For most AppleScript purposes, I don't think that the following is
very useful, but you may find it handy:


script myObject
property occupation : ""

on updateObj()
set my occupation to "janitor"
set my income to 500
end updateObj

end script

set myObject to AddIncomeToAnyObject(myObject, 0)

myObject's occupation --> ""
myObject's income --> 0

myObject's updateObj()

myObject's occupation --> "janitor"
myObject's income --> 500

on AddIncomeToAnyObject(script_object, income_amount)

script temp_script
property parent : script_object
property income : income_amount
end script

return temp_script

end AddIncomeToAnyObject


{ Arthur J. Knapp, of <http://www.STELLARViSIONs.com>
<mailto:email@hidden>
try
<http://www.goodbuddy.net/budco/sware/imscripts.htm>
on error number -128
end try
}
_______________________________________________
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.

  • Follow-Ups:
    • Re: script object properties: seeking confirmation
      • From: Bill Hoffman <email@hidden>
  • Prev by Date: Re: Finder tell block
  • Next by Date: Re: Opening SD's EnclosingFolder
  • Previous by thread: Re: script object properties: seeking confirmation
  • Next by thread: Re: script object properties: seeking confirmation
  • Index(es):
    • Date
    • Thread