Hi,
I am trying to make an xml photo gallery for so many days but constantly getting errors, don’t understand why? Please help me…
Here is the XML file:
<images>
<pic>
<img>thumb_winter</img>
<captions>Winter</captions>
</pic>
<pic>
<img>blue_hill</img>
<captions>Blue Hill</captions>
</pic>
</images>
And here is the AS 3.0 code:
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.xml.*;
var list:XMLList= new XMLList();
var loader:URLLoader = new URLLoader();
var req:URLRequest = new URLRequest("images.xml");
loader.load(req);
loader.addEventListener(Event.COMPLETE, onComplete);
function onComplete(ev:Event):void
{
try {
if(loader != null)
{
var loader:URLLoader = URLLoader(ev.target.data);
var result:XML = new XML(loader.data);
var data_xml:XMLDocument = new XMLDocument();
data_xml.ignoreWhite = true;
var node:XMLNode = data_xml.firstChild;
text_txt.text = node.firstChild.attributes['captions']; //added for testing
this.addChild(text_txt);
}
else {
trace("File not loaded");
}
}
catch(error:Error)
{
trace("Error Encountered");
}
}
When I run this code…it catches the error & shows “Error Encountered”. If I remove try…catch statements…it shows
to flash.net.URLLoader.
at photo_fla::MainTimeline/onComplete()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
I am writing this on main timeline & not making .as file.
Also, how can I show a photo on stage using pic_mc (a movieclip)…I am badly confused because of errors & all.
P.S.
On stage I have:
- pic_mc (a movie clip…Picture holder)
- Previous & next buttons (to navigate through pictures)
- text_txt ( a dynamic text box to show picture description)
- pos_txt ( a dynamic text box to show picture number i.e. 2 out of 10)