PDA

View Full Version : AS3: conditional statement to determine if an xml child is null... help!



wuzzi2ya
June 16th, 2009, 04:17 PM
With this code, I need to determine if the xml child is null and form a conditional statement upon that info. I have it very close but something is just "un-tweeked" enough that it wont work correctly. AS3 and XML provided below...

Thanks!

AS3:

var url = txtBox_mc.getTix.url;
var request:URLRequest = new URLRequest(url);
txtBox_mc.getTix.addEventListener(MouseEvent.CLICK , GetUrTix);
function updatePic(index:int):void {
txtBox_mc.getTix.url = picList[index].url;
if (url == null) {
txtBox_mc.getTix.visible = false;
trace("button null");
} else {
txtBox_mc.getTix.visible = true;
trace("button there");
}
txtBox_mc.EventHeader.htmlText = picList[index].caption1;
txtBox_mc.EventDate.htmlText = picList[index].caption2;
txtBox_mc.EventPlace.htmlText = picList[index].caption3;
trace(picList[index].url);
trace(picList[index].caption1);
trace(picList[index].caption2);
trace(picList[index].caption3);
trace(index);
}
function GetUrTix(event:MouseEvent):void {
navigateToURL(request);
trace("gettin some tix");
}
XML:

<slideshow>
<image>
<url>http://www.yahoo.com</url>
<caption1>This is the show</caption1>
<caption2>September 14-15</caption2>
<caption3>Where Else</caption3>
</image>
<image>
<caption1>What a Show</caption1>
<caption2>August 14-15</caption2>
<caption3>Where is It</caption3>
</image>
<image>
<url>http://www.cubiccreative.com</url>
<caption1>Jazz Hands</caption1>
<caption2>December 14-15</caption2>
<caption3>Tuen Left at the Sign</caption3>
</image>
</slideshow>
The problem now only the " if (url == null) { " is read, thus returning those results. I believe the issue is within the definition of url " var url = txtBox_mc.getTix.url; "...
Any help is greatly appreciated!

JonnyR
June 16th, 2009, 04:53 PM
Hi Wuzzi2ya,

I suspect the problem is coming from the way you are parsing the XML and storing it in the picList Array (but you've haven't included said code, so I can't be 100% sure).

However, in leiu of that, you could try the following:



if (String(url) == "")


Let me know if that sorts the issue for you.
Jonny.

wuzzi2ya
June 16th, 2009, 05:13 PM
Thanks for the reply...

The xml is loaded in in this fashion:



var xmlData:XML = new XML();
var picList:XMLList = new XMLList();
var currentPic:int = 0;
var url = txtBox_mc.getTix.url;
var request:URLRequest = new URLRequest(url);
loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest("slideshow.xml"));


function onComplete(e:Event):void {
myTimer.start();
xmlData = new XML(loader.data);
picList = xmlData.image;
updatePic(currentPic);
}

then:

function updatePic(index:int):void {
txtBox_mc.getTix.url = picList[index].url;
if (url == null) {
txtBox_mc.getTix.visible = false;
trace("button null");
} else {
txtBox_mc.getTix.visible = true;
trace("button there");
}
txtBox_mc.EventHeader.htmlText = picList[index].caption1;
txtBox_mc.EventDate.htmlText = picList[index].caption2;
txtBox_mc.EventPlace.htmlText = picList[index].caption3;
trace(picList[index].url);
trace(picList[index].caption1);
trace(picList[index].caption2);
trace(picList[index].caption3);
trace(index);
}

wuzzi2ya
June 16th, 2009, 06:59 PM
Also I dont believe a string will work as the url within the xml is actually going to be determined by an asp input field...