Class that provides a dynamic implimentation of the URLLoader class. This class provides no API implimentations. However, since the class is declared as dynamic, it can be used in place of URLLoader, and allow you to dynamically attach properties to it (which URLLoader does not allow). This class is simple but useful when you want to transfer arguments together with URLLoader.
Demo
This demo loads external XML with an instance of DynamicURLLoader and attach the URL of XML file as a property of the instance. When the loading is complete, show the URL of the XML as the status of the main panel according to the attached property url of the complete event target. Meantime, set the dataProvider property of the list according to the data property of the complete event target.
data.xml
<?xml version="1.0" encoding="utf-8"?> <images> <image name="folder_apple_close" path="assets/images/folder_apple_close.png"/> <image name="folder_apple_with_file" path="assets/images/folder_apple_with_file.png"/> <image name="folder_apple" path="assets/images/folder_apple.png"/> <image name="folder_cd" path="assets/images/folder_cd.png"/> <image name="folder" path="assets/images/folder.png"/> </images>
DynamicURLLoaderDemoBehind.as
package
{
import com.adobe.net.DynamicURLLoader;
import flash.events.Event;
import flash.net.URLRequest;
import mx.collections.XMLListCollection;
import mx.controls.List;
import mx.core.Application;
public class DynamicURLLoaderDemoBehindextends Application
{
public function DynamicURLLoaderDemoBehind()
{
super();
}
public var imageInfoList:List;
[Bindable]
private var dynamicLoader:DynamicURLLoader;
[Bindable]
protected var status:String;
protected function loadData():void
{
if(!dynamicLoader)
{
dynamicLoader = new DynamicURLLoader();
dynamicLoader.addEventListener(Event.COMPLETE, onLoadXML);
}
////////////////////////////////////////
//
// url of dynamicLoader is an attached
// property.
//
dynamicLoader.url = "assets/data/data.xml";
//
////////////////////////////////////////
dynamicLoader.load(new URLRequest(dynamicLoader.url));
status = "loading data";
}
private function onLoadXML(event:Event):void
{
status = "loaded data from " + event.target.url;
imageInfoList.dataProvider = new XMLListCollection(XML(event.target.data).children());
}
}
}
DynamicURLLoaderDemo.mxml
<?xml version="1.0" encoding="utf-8"?>
<DynamicURLLoaderDemoBehind
xmlns="*"
xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute">
<mx:Panel
title="DynamicURLLoader Demo"
width="100%"
height="100%"
status="{status}"
>
<mx:List id="imageInfoList"
labelField="@name"
itemClick="image.source = imageInfoList.selectedItem.@path"/> <mx:Image id="image"/> <mx:ControlBar>
<mx:Button label="Load Images Info" click="loadData()"/>
</mx:ControlBar>
</mx:Panel>
</DynamicURLLoaderDemoBehind>
Enjoy!

January 15th, 2009
Ntt.cc
Posted in
Tags: 
RSS Feed
Email Feed
Hi
I have a project where i have a flex application that launches a.swf file and need’s to add a uri value to the .swf, and i am not sure how to begin with this.
The .swf file currently has a datainput field where you can manually type the uri value, but i need the flex input value to automatically overwrite or be added to this component….
This is pulling my hair out, any help would be much appreciated. I would even compensate someone for helping me here as i have a deadline approaching.
Regards
steve