Expand my Community achievements bar.

Dive into Adobe Summit 2024! Explore curated list of AEM sessions & labs, register, connect with experts, ask questions, engage, and share insights. Don't miss the excitement.

Loading External XML

Avatar

Level 1
I am using code given in the flex help to load a external
xml. But it generated error "Access to undefied property loader."



My mxml file code is as below:





<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
xmlns="*"

layout="vertical" >



<mx:Script>

<![CDATA[

import flash.events.Event;

import flash.net.URLLoader;

import flash.net.URLRequest;



var externalXML:XML;

var loader:URLLoader = new URLLoader();

var request:URLRequest = new URLRequest("
http://localhost/work/rnd/images.xml");

loader.load(request);

loader.addEventListener(Event.COMPLETE, onComplete);



function onComplete(event:Event):void

{

var loader:URLLoader = event.target as URLLoader;

if (loader != null)

{

externalXML = new XML(loader.data);

xmlText.text = (externalXML.toXMLString());

}

else

{

trace("loader is not a URLLoader!");

}

}

]]>

</mx:Script>

<mx:HBox width="400">

<mx:Label text="xml:"/>

<mx:TextInput id="xmlText" width="100%"
enter="mainTxt.text = myGreeter.sayHello(userNameTxt.text);" />

</mx:HBox>

</mx:Application>



2 Replies

Avatar

Level 1
Try this... you need to make sure you call the code after the
page is created via creationComplete="init()".



<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml"
xmlns="*" layout="vertical" creationComplete="init()">



<mx:Script>

<![CDATA[

import flash.events.Event;

import flash.net.URLLoader;

import flash.net.URLRequest;



public function init():void{

loadXML();

}



public function loadXML():void{



var externalXML:XML;

var loader:URLLoader = new URLLoader();

var request:URLRequest = new URLRequest("
http://localhost/work/rnd/images.xml");

loader.load(request);

loader.addEventListener(Event.COMPLETE, onComplete);



}



function onComplete(event:Event):void

{

var loader:URLLoader = event.target as URLLoader;

if (loader != null)

{

externalXML = new XML(loader.data);

xmlText.text = (externalXML.toXMLString());

}

else

{

trace("loader is not a URLLoader!");

}

}

]]>

</mx:Script>

<mx:HBox width="400">

<mx:Label text="xml:"/>

<mx:TextInput id="xmlText" width="100%"
enter="mainTxt.text = myGreeter.sayHello(userNameTxt.text);" />

</mx:HBox>

</mx:Application>

Avatar

Former Community Member
I hit this same issue a couple of weeks ago and posted the
same question in the general forum which was answered by Greg
Lafrance with the same answer that eonestudio gave you. (A hint to
search next time.)