UDN
Search public documentation:

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

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 pass an array of Objects to ActionScript

How to pass an array of Objects to ActionScript


Overview


This is a quick guide to demonstrate how you would pass an array of Objects to and fro Unrealscript and Actionscript.

From Unrealscript to ActionScript


UnrealScript
/** Item struct */
struct Items
{
  var string ItemName;
  var string ItemType;
  var string ItemDesc;
};

var array<Items> Inventory;

function SetUpInventory()
{
  local byte i;
  local GFxObject DataProvider;
  local GFxObject TempObj;
  local GFxObject RootMC;
   
  RootMC = GetVariableObject("_root");

  DataProvider = CreateArray();
   
  for (i = 0; i < Inventory.Length; i++)
  {        
    TempObj = CreateObject("Object");
    TempObj.SetString("ItemName", Inventory[i].ItemName);
    TempObj.SetString("ItemType", Inventory[i].ItemType);
    TempObj.SetString("ItemDesc", Inventory[i].ItemDesc);
    DataProvider.SetElementObject(i, TempObj);
  }

  RootMC.SetObject("inventory", DataProvider);     
  ShowInventory();
}

function ShowInventory()
{
  ActionScriptVoid("showInventory");
}

ActionScript
var inventory:Array = [];

function showInventory()
{
  for (i:Number = 0; i < inventory.length; i++)
  {
    trace("Name: " + inventory[i].ItemName + " | Type: " + inventory[i].ItemType + " | Description: " + inventory[i].ItemDesc);
  }
}

From ActionScript to Unrealscript


UnrealScript
function ListInventory()
{
  local GFxObject Item;

  // Method 1
  // These lines return the name, type, and description of the inventory item stored at element 0 of the inventory[] array in the Flash file.
  `log("Item Name: " @ RootMC.GetObject("inventory").GetElementMemberString(0, "ItemName"));
  `log("Item Type: " @ RootMC.GetObject("inventory").GetElementMemberString(0, "ItemType"));
  `log("Item Description: " @ RootMC.GetObject("inventory").GetElementMemberString(0, "ItemDesc"));
   
  // Method 2
  // This version first caches a reference to the GFxObject{} found at element 0 of the inventory[] array.
  Item = RootMC.GetObject("inventory").GetElementObject(0);

  `log("Item Name: " @ Item.GetString("ItemName"));
  `log("Item Type: " @ Item.GetString("ItemType"));
  `log("Item Description: " @ Item.GetString("ItemDesc"));
}