Report progress while loading SWFs and Images in SWFLoader
You canload content into your Adobe Flex or Adobe AIR application while it's running, such as images (GIF. JPEG, PNG) or other SWF files that provide more functionality to your application. The SWFLoader control in Flex is capable of loading these files, and is also capable of reporting progress as it loads.
To load an image or SWF using the SWFLoader control and report progress, status, and errors:- Create a new Project in Flex, or create a new MXML Application within an existing project.
- Paste the code below into your new MXML file.
- Run the Application, and click the "Load Image" button to load a sample image.
- In the source code, you may edit the target in SWFLoader1.load (in the loadSWF function) to any valid GIF, PNG, JPEG or SWF file.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" >
<mx:Script>
<![CDATA[
private function loadProgress(event:ProgressEvent):void
{
var pctLoaded:Number = Math.round((event.bytesLoaded / event.bytesTotal) * 100);
LoadPercent.text = ("Loaded:" + pctLoaded + "%");
}
private function loadComplete(event:Event):void
{
LoadStatus.text = ("Done");
}
private function loadError(event:IOErrorEvent):void
{
LoadError.text = (event.text) + "\r";
}
private function LoadSWF():void
{
LoadStatus.text = "Loading...";
// The larger the image or SWF you load, the better you will see
// the progress % increase
SWFLoader1.load("http://URL TO IMAGE OR SWF");
}
]]>
</mx:Script>
<mx:Canvas id="justforlooks" x="10" y="78"
backgroundColor="#C9C9C9" borderStyle="solid" borderColor="#B7BABC"
alpha="1.0" cornerRadius="0"/>
<mx:Button click="LoadSWF()" label="Load Image" x="10" y="10"/>
<mx:SWFLoader id="SWFLoader1" x="9" y="76"
progress="loadProgress(event)" complete="loadComplete(event)"
ioError="loadError(event)" alpha="1.0" themeColor="#000000"/>
<mx:Label x="112" y="10" text="Percent Loaded" id="LoadPercent"/>
<mx:Label x="112" y="31" text="Status" id="LoadStatus"/>
<mx:Label x="112" y="52" text="No Error" id="LoadError"/>
</mx:Application>
Additional Information
Refer to the LiveDoc on SWFLoader for more information: http://livedocs.adobe.com/flex/2/langref/mx/controls/SWFLoader.html
This content requires Flash
To view this content, JavaScript must be enabled, and you need the latest version of the Adobe Flash Player.
Download the free Flash Player now!
