36 The Code. Toggles + Radio buttons. 1
 
    From:       zavpublic-spamblock-mac.com
    Subject:     Re: [DIRECT-L] UI framework code. Toggles + Radio buttons. 1
    Date:     February 2, 2007 4:58:22 PM CST
    To:       DIRECT-L-spamblock-LISTSERV.UARK.EDU
    Reply-To:       DIRECT-L-spamblock-LISTSERV.UARK.EDU
 
 
Now, If you have read my last email on the additional untouched on functionality present in the button scripts, I have added the graphic loader script and the "point to another graphic for my state" script ( scripts 91- 93).  Feel free to try them out and ask me stuff about them.
 
To make toggle buttons, we have a little more states than most would expect.
 
As mentioned before, we have the four standard button states.  Now, by adding the toggled state, we have four additional states, which are the same four of before but in the toggled state.
 
Name wise, it makes the best sense to add the word "toggled" to the name of the button to define that it is indeed toggled.  Since the last word of the button name is expected to indicate the basic state, the text "toggled" must be the second to last word in the graphic name.  This is not ideal but it is pretty near more than good enough.
 
Therefore, if I were being silly and named a check box/toggle button, oooohhhhh, saaaaayyyy, "Greenium", the names for all eight graphics would be:
 
Greenium Check Box Active
Greenium Check Box Rollover
Greenium Check Box Down
Greenium Check Box Disabled
Greenium Check Box Toggled Active
Greenium Check Box Toggled Rollover
Greenium Check Box Toggled Down
Greenium Check Box Toggled Disabled
 
Note that we will also need different masks for each since many check boxed actually have a check in the checked stated.  This means that the mask sprite must change as well so we will need the checked and unchecked masks.  (Don't forget to use MATTE ink here, not mask.)
 
Greenium Check Box Mask
Greenium Check Box Toggled Mask
 
Thankfully, someone who looks a lot like me thought of this on 12 27, 2001 and did this for you.
 
To create the simplest toggle button only requires the above and one additional script.
 
To create this alleged "simplest toggle evar", please follow the recipe below.
- Select members 141 and 145, Greenium Active and the Greenium Active Mask
- Drag them to the stage and color the mask sprite Orange.
- Set the ink of the mask sprite to MATTE, at a 0 blend
- Apply the following behaviours:
    2: Button sprite specific subclass - sprite - 1
    101: Root Toggle button sprite subclass
- Rewind and run.
 
That's it.  We have a toggle.
 
Now, you can ask sprite 3 if it is toggled by doing this:
put sendsprite(3, #IsToggled)
and it will return either 0, 1, or <Void> but this is poor (bad) form.  You should be setting properties in a master object when a toggle button toggles.  You should NEVER EVER be querying a toggle button.  It is a creature of broadcasting its state to others who need to hear so your success script should be sending the pIsToggled value to whatever object needs to know if it is on or off.
And also, I said we don't care about sprite numbers anymore so we just can't do that.  It's not that the code's not there.  We really just shouldn't do that.
 
For a full fledged toggle button/check box, with text next to it that ALSO clicks the toggle button, we should add a few more behaviours and make the toggle a "standard" named sprite.  For mouse actions that happen over/on the button's text, an event relay script tells the toggle button to act as if the mouse is over it!  A man less humble than I would proclaim the creator of this concept a certified genius, which is exactly what I did in my less humble days.
 
To set this up, add the following scripts to the toggle button mask:
"Register/Unregister button based on name of the button graphic"
"Change cursor on rollover to hand"
 
Your script order should be:
Button sprite specific subclass - sprite - 1
Register/Unregister button based on name of the button graphic
Change cursor on rollover to hand
Root Toggle button sprite subclass
 
Before running the movie, make sure you have inited the registry in preparemovie. (Hint: use InitRegistry)
 
Run the movie and type GetAllButtonNames in the massage window.
You should get:
-- ["Greenium Check Box"]
 
Stop the movie and drag cast member 181 to the score and set background transparent ink for it.
Apply behaviour 102 to it.  Set the Target Button Name to "Greenium Check Box" sans quotes.
Check the following check boxes for events:
MouseEnter
MouseLeave
MouseWithin
MouseUp
MouseDown
MouseUpOutside
 
One might think that one who has called once himself a genius would have set these to be on in the defaults.  And I just might do that.
 
Run the movie and have fun clicking on the text.
 
More soon.
 
- Zav
 
---
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