UDN
Search public documentation:

CLIKCheckBox
日本語訳
中国翻译
한국어

Interested in the Unreal Engine?
Visit the Unreal Technology site.

Looking for jobs and company info?
Check out the Epic games site.

Questions about support via UDN?
Contact the UDN Staff

UE3 Home > User Interfaces & HUDs > Scaleform GFx > How to get and set a check box value

How to get and set a check box value


Overview


This tutorial shows you how to set or get a value from a check box.

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:

Unrealscript
var GFxClikWidget MyCheckBox;
var bool MyOption;

event bool WidgetInitialized(name WidgetName, name WidgetPath, GFxObject Widget)
{
  switch(WidgetName)
  {
  case ('aCheckBox'):
    MyCheckBox = GFxClikWidget(Widget);
    if (MyCheckBox  != None)
    {
      MyCheckBox.AddEventListener('CLIK_select', OnMyCheckBoxChange);
    }
    break;

  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'))
}

ALERT! 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:

Unrealscript
MyOption = MyCheckBox.GetBool("_selected");

Setting a Checkbox's Value


To set a checkbox from UnrealScript:

Unrealscript
MyCheckBox.SetBool("selected", true); // or false

or...

Unrealscript
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:

ActionScript
function SetMyCheckBox(checked:Boolean)
{
  aCheckBox.selected = checked;
}