Now time to write code that actually does something! Loading our XML! We need to import a couple of classes to load our data, the URLRequest class, all the events class package (we’ll need those) events.*, the TextField class that we’ll use to show our XML, and the URLLoader class. We also declare a few member variables: A variable to hold our XML data “var picture_xml:XML;”, a variable to hold our URLRequest “var url_request:URLRequest;”, and a variable to hold our URLLoader “var url_loader:URLLoader;”:

package {
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLLoader;
public class LoadingData extends Sprite
{
var picture_xml:XML
var url_request:URLRequest;
var url_loader:URLLoader;
public function LoadingData()
{
}
}
}

Now in our constructor we are going to instantiate our URLRequest, and URLLoader variables, write some code to initiate the loading and add a COMPLETE event to trigger a function when the XML data is fully loaded:

package {
import flash.display.Sprite;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.events.*;
import flash.text.TextField;
public class LoadingData extends Sprite
{
var picture_xml:XML
var url_request:URLRequest;
var url_loader:URLLoader;
public function LoadingData()
{
url_request = new URLRequest("slide_show.xml");
url_loader = new URLLoader();
url_loader.addEventListener(Event.COMPLETE, completeHandler);
url_loader.load(url_request);
}
private function completeHandler(e:Event):void{
picture_xml = new XML(url_loader.data);
var txt:TextField = new TextField();
txt.width = stage.stageWidth;
txt.height = stage.stageHeight;
txt.wordWrap = true;
txt.text = picture_xml;
addChild(txt);
}
}
}

If everything went well you should like me see our XML displayed in our textfield. Now to be truly dynamic our slide show should be able to load different XMLs. For example you should be able to display two slide shows in the same html page with different pictures which means loading different XMLs. We can do so by using FlashVars.