UDN
Search public documentation:

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

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 access Unrealscript variables within an external SWF

How to access Unrealscript variables within an external SWF


Overview


Just a quick tutorial showing how you might go about reading (or pulling) a variable from UnrealScript into your Flash file (rather than pushing it from UnrealScript).

ActionScript
var retVal:Object = {};
retVal = ExternalInterface.call("GetUnrealVariable", "someFloat", "float");
// Parameter 2 = the variable name in UnrealScript.
// Parameter 3 = the variable type in UnrealScript - float, string, etc.

trace("My UnrealScript Variable: " + retVal.someFloat);

Unfortunately, it does not seem to be the case that you can use a dynamic variable name in UnrealScript, like you can in ActionScript. If you could, we could simply write something like: asval.n = VarName; Since you can't, this is a hacky solution, which requires you to put a case for every UnrealScript variable you would want access to in Flash in a switch statement.

Unrealscript
var float someFloat;
var string someString;
var bool someBoolean;

someFloat = 1337;
someString = "Boo!";
someBoolean = true;

function GFxObject GetUnrealVariable(string VarName, string VarType)
{
  local GFxObject TempObj;
  local ASValue asval;
  local array<ASValue> args;

  TempObj = CreateObject("Object");
  switch(VarType)
  {
  case ("float"):
    asval.Type = AS_Number;
    break;

  case ("string"):
    asval.Type = AS_String;
    break;

  case ("bool"):
    asval.Type = AS_Boolean;
    break;

  default:
    break;
  }

  switch(VarName)
  {
  case ("someFloat"):
    asval.n = someFloat;
    break;

  case ("someString"):
    asval.s = someString;
    break;

  case ("someBoolean"):
    asval.b = someBoolean;
    break;

  default:
    break;
  }

  args[0] = asval;
  TempObj.Set(VarName, args[0]);

  return TempObj;
}