The last functional piece to deal with is the user interface
for the asset explorer. In this example, the path to the run-time
library is hard-coded as a variable named
ASSETS_PATH
.
Alternatively, you could use the FileReference class—for example,
to create an interface that browses for a particular SWF file on
your hard drive.
When the run-time library is successfully loaded, Flash Player
calls the
runtimeAssetsLoadComplete()
method:
private function runtimeAssetsLoadComplete(event:Event):void
{
var rl:* = event.target.content;
var assetList:Array = rl.getAssets();
populateDropdown(assetList);
stage.frameRate = 60;
}
In this method, the variable rl represents the loaded SWF file.
The code calls the
getAssets()
method of the loaded
SWF file, obtaining the list of assets that are available, and uses
them to populate a ComboBox component with a list of available assets
by calling the
populateDropDown()
method. That
method in turn stores the full classpath of each asset. Clicking
the Add button on the user interface triggers the
addAsset()
method:
private function addAsset():void
{
var className:String = assetNameCbo.selectedItem.data;
var AssetClass:Class = getDefinitionByName(className) as Class;
var mc:MovieClip = new AssetClass();
...
}
which gets the classpath of whichever asset is currently selected
in the ComboBox (
assetNameCbo.selectedItem.data
),
and uses the
getDefinitionByName()
function (from
the flash.utils package) to obtain an actual reference to the asset’s
class in order to create a new instance of that asset.