Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: control object names



> Message: 2
> Date: Wed, 20 Sep 2006 09:24:54 -0500
> From: "RJay Hansen" <email@hidden>
> Subject: control object names
> To: "AppleScript Studio Mailing List"
> <email@hidden>
> Message-ID:
> <email@hidden>
> Content-Type: text/plain; charset=ISO-8859-1; format=flowed
> 
> Quick question.
> 
> If you have two windows w/similar controls, is it a problem to assign
> the same name to a similar control in each window?
> 
> For example, the default button on two different windows may be a
> "Save" button. Could you name them both "saveNow" as long as you
> specified which window they were attached to when addressing them (eg.
> button "saveNow" of window "mainWindow")?


Actually, sometimes it makes sense to name them all the same if they do the
same thing.  In code, you could handle them like:

on clicked theObject
    set theName to (name of theObject) -- should be a string
    if theName is equal to "saveNow" then
        -- do something here
    else if theName is equal to "somethingElse"
    .
    etc...
    .
    end if
end clicked

I would only give the buttons separate names and/or sort them by which
window they belong to if they were doing different things.  You can also use
the same button name (as above) but use the tag of the button to determine a
second level of identification or carry auxiliary data:

on clicked theObject
    set theName to (name of theObject)
    set theTag to (tag of the Object) -- an integer
    if theName is equal to "saveNow" then
        goDoSomething(theTag)
    else if theName is equal to "somethingElse"
    .
    etc...
    .
    end if
end clicked

Whatever you do to minimize the number of if statements inside the on
clicked handler is good for app responsiveness.

Craig

-- 
Dr. Craig Hunter
NASA Langley Research Center
Configuration Aerodynamics Branch
email@hidden
(757) 864-3020


 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Applescript-studio mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/applescript-studio/email@hidden

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.