Announcement

Collapse
No announcement yet.

[CLIK] Getting & Setting Checkbox Values

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [CLIK] Getting & Setting Checkbox Values

    Getting a Checkbox's Value

    The following UnrealScript will allow you to get the value of a checkbox, assuming your checkbox has an instance name in Flash of 'aCheckBox' and assuming you're using a CLIK widget for that checkbox:

    Code:
    var GFxClikWidget MyCheckBox;
    var bool MyOption;
    
    event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
    {    
        switch(WidgetName)
        {                 
            case ('aCheckBox'):
                MyCheckBox = GFxClikWidget(Widget);
                MyCheckBox.AddEventListener('CLIK_select', OnMyCheckBoxChange);
            default:
                break;
        }
        return true;
    }
    
    function OnMyCheckBoxChange(GFxClikWidget.EventData ev) 
    {
        MyOption = MyCheckBox.GetBool("_selected");
        `log("aCheckBox has been set to: "@MyOption);
    }
    
    defaultproperties
    {    
        WidgetBindings.Add((WidgetName="aCheckBox",WidgetClass=class'GFxClikWidget'))
    }
    NOTE: While you could use CLIK_press as the event to listen for, this would yield the previous state of the checkbox and not the current state. CLIK_select ensures you get the current state of the checkbox AFTER the user pressed the checkbox button and not before. Of course, getting the current state of the checkbox, without waiting for the user to click on it, is simply a matter of using the code:

    Code:
    MyOption = MyCheckBox.GetBool("_selected");
    Setting a Checkbox's Value

    To set a checkbox from UnrealScript:

    Code:
    SetMyCheckBox(true); // true or false
    
    function SetMyCheckBox(bool b) 
    {
        ActionScriptVoid("SetMyCheckBox"); // passes the boolean value stored in 'b' to the AS function SetMyCheckBox
    }
    In ActionScript (in your Flash file on the keyframe where the checkbox instance lives), you should have the following code, which will set the checkbox's value appropriately as well as setting the checkbox movie clip to the correct keyframe which will then display either a check or no check:

    Code:
    function SetMyCheckBox(checked:Boolean) 
    {
        aCheckBox.selected = checked;
    }
Working...
X