UDN
Search public documentation:

GFxObjectArrayCH
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 > 如何将一个Object(对象)的数组传输到ActionScript(动作脚本)

如何将一个Object(对象)的数组传输到ActionScript(动作脚本)


概述


这个教程指导您如何在Unrealscript(虚幻脚本)和ActionScript(动作脚本)之间传输Object(对象)的数组。

从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"));
}