UDN
Search public documentation:

GFxObjectArrayJP
English Translation
中国翻译
한국어

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 ホーム > ユーザーインターフェイスと HUD > 「Scaleform GFx」 > オブジェクトの配列を ActionScript に渡す方法

オブジェクトの配列を ActionScript に渡す方法


概要


本ドキュメントでは、UnrealScript と ActionScript 間でオブジェクトの配列を受け渡す方法について、その概略を示しています。

UnrealScript から 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);
  }
}

ActionScript から 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"));
}