29 The Code. Part 3.2
 
    From:       zavpublic-spamblock-mac.com
    Subject:     Re: [DIRECT-L] UI framework code. Named Sprites. Part 3.2
    Date:     January 31, 2007 5:04:06 PM CST
    To:       DIRECT-L-spamblock-LISTSERV.UARK.EDU
    Reply-To:       DIRECT-L-spamblock-LISTSERV.UARK.EDU
 
On Jan 31, 2007, at 1:27 PM, prothero wrote:
 
Now that we have named buttons in Director, why might you want to use these as opposed to simply naming the sprite in the sprite channel?  Director's named sprites can't be created on demand.  You can't set the name of a sprite at runtime.  Here, button entities name themselves when they come into existence and remove their name record when they disappear from the score.  There is also more than one one way to name a button.  Behaviours with PDLs allow you to enter the name if you do not wish it to be grabbed from the member's name.  This is good to prevent duplicate name entries.  So this approach is rather flexible.
 
Naming buttons is also required if you want them to work with each other.  Radio button groups require this.  Additionally, if you have a group, this can also be registered by name as well, so you can tell an entire group to do something if needed.
 
But before we get to that, you may have noticed a large amount of additional "support" code in the latest example.  What does it all do and allow you to do?
 
Now that we have a button registry for named buttons, we also have an entire movie script API for working with these buttons.  We'll need this when we get to button groups but they are pretty useful right now.  Here's what is present and what it does.  You can try these in the message window.
 
I recommend trying
ToggleAllButtons
EnableAllButtons
DisableAllButtons
EnableButton "Login"
DisableButton "Login"
EnableButton "Logout"
DisableButton "Logout"
ToggleMasks
 
This is not that useful with two buttons but on a complex UI where things need to turn on and off, it is MUCH easier to remember the button names and enable, disable, allocate, deallocate on the fly and manage them by name.  When we get to Dialogs, you'll see what I mean.
 
Script: InitRegistry
InitRegistry
    Init the button registry.  Best done in PrepareMovie.  Must be done before you try to put a registered button on the stage.
 
ClickButton myButtonName
    Tell a registered button to perform a click.
 
Script: Named Button State Change broadcast scripts
EnableButton myButtonName
    If a button is in the disabled state, tell it to be enabled.
 
DisableButton myButtonName
    If a button is in the enabled state, tell it to be disabled.
 
ToggleButton myButtonName
    Switch the enabled state of the button to what it is not.
    
EnableAllButtons
    Enable all the registered buttons.
 
DisableAllButtons
    Disable all the registered buttons.
 
ToggleAllButtons
    Switch the enabled state of all registered buttons to that which they are not.
 
ToggleButtonList myButtonList
    Switch the enabled state of the list of button names.
 
EnableButtonList myButtonList
    Enable all buttons in the registry that are in the supplied button name list.
 
DisableButtonList myButtonList
    Disable all buttons in the registry that are in the supplied button name list.
 
MessageButton myButtonName
    Send a handler call to a registered button.
 
ButtonExists myButtonName
    Return if the button exists in the registry.
 
ButtonDoesNotExist myButtonName
    Return if the button exists in the registry.
 
There are many more within the Registry API but that might be a little much for now.
Note that there are utility scripts that help you make the buttons
 
CopyScriptList
    Assuming you have set up the basic scriptlist on one button, this copies it to another button mask sprite so there is less clicking for you to do.
 
ShowMasks
HideMasks
ToggleMasks
    The handlers above apply or remove a blend to the mask sprites so you can see if they match up properly with their graphic sprites.
 
InitDebug -- MISSING
EnableDebug
DisableDebug
ToggleDebug
    The handlers above set a global called gDebug.  The capability to trace what handler the button code is going through is built in to the button code.  For this to work, you need a text field named "Output" that will contain the result of the debug output.  InitDebug must be called prior to using these commands.  Unfortunately, I forgot to include it.  It should be called in PrepareMovie and the missing code should go in script 82.  The missing code looks like this:
 
on InitDebug
 Init script "debug"
end
 
What does the other stuff do?  Since some of these things depend on others to start up, I have included a "service dependency checker" modeled off of an approach used in OS X where if you attempt to call something that depends on other stuff being started up, it will tell you what stuff needs to be started up.  This is only applied where a service is started that needs other services.  If you try to init the Control Registry script before init the Registry master control db object, it will tell you.  This is useful to me, but if you init the proper routines by using the movie scripts, you'll never need to worry about these.
 
Next: Button groups.
 
---
Macromedia Director Mailing List (Direct-L)
List Administrator:  Eve M. Owens (emowens-spamblock-theserver.uark.edu)
 
To SUBSCRIBE or to UNSUBSCRIBE go to
and click on
"Join or leave the list (or change settings)"
 
For list archives
 
 
Learning Zav’s Libraries