Scaleform CLIK components such as
ScrollingList get their data from an
IDataProvider simply represents a way to populate a component with data. The included
IDataProvider implementation in Scaleform,
DataProvider, gets its data from an array.
var redTeamPlayerList.dataProvider = new DataProvider(["Player 1", "Player 2", "Player 3"]);
This is great if the data is generated in ActionScript. However, the data we want is usually generated in the game code, not in ActionScript. To get data from the game, you can use ExternalDataProvider, an
IDataProvider implementation that is fully compatible with the existing
DataProvider in Scaleform.
ExternalDataProvider works by using
ExternalInterface to call a source function in the game code that returns an array of data for the component. An UnrealScript function that returns an array of data could look like this:
function array<string> GetPlayerNames(string TeamName)
local array<string> Data;
local PlayerReplicationInfo PRI;
local byte TeamIndex;
TeamIndex = TeamName ~= "red" ? 0 : 1;
if (PRI.Team != None && PRI.Team.TeamIndex == TeamIndex)
Back in ActionScript, you can hook up a component to this data by setting its
dataProvider to an
ExternalDataProvider that calls the defined function.
redTeamPlayerList.dataProvider = new ExternalDataProvider("GetPlayerNames", "red team");
The component is now hooked up to the specified game data. Whenever the component is displayed, it will automatically call the source function to get an array of data to populate the component.
If the source data changes while the component is displayed, the component needs to be invalidated in order to update itself with the new data.
ExternalDataProvider, the work of transferring game information from the game to Scaleform is automated. The only setup required is to define the source function in the game code.