I have an XML file and in the file there is a node called <content>. This content can have one of two child nodes <flashID> or <loadUrl>. I have a function called videoList. Here I am using a switch case statement. Where I am running into problems is trying to determine which menu item <categoryName> has a video and play it.
In my videoList, case “Our Work” does not have any video urls associated with it. Yet when I click on this button in my clipClick function, the menu, it plays a video. How do I write my clipClick function or videoList function to check for when the <loadUrl> is present in the <content>. I hope that makes sense.
//put button names from XML into an array
var categoryNames:Array;
//create menu
function createMenu():void {
//get info
for each (var node:XML in navData) {
//trace(node.name.toString());
infoName=node.info.name.toString();
infoClient=node.info.client.toString();
infoCreator=node.info.creator.toString();
//
infoContactCompany=node.info.contactCompany.toString();
infoContactName=node.info.contactName.toString();
infoContactEmail=node.info.contactEmail.toString();
//
infoSalesName=node.info.salesName.toString();
infoSalesEmail=node.info.salesEmail.toString();
infoSalesPhone=node.info.salesPhone.toString();
//place text in text fields
pname.text=infoName;
client.text=infoClient;
creator.text=infoCreator;
}
//Determine unique category names
categoryNames=[];
var categories:XMLList=navData..categoryName;
for (var i:int = 0; i < categories.length(); i++) {
var categoryName:String=categories*;
if (categoryNames.indexOf(categoryName)==-1) {
categoryNames.push(categoryName);
}
}
// Build menu based on categories
for (i = 0; i < categoryNames.length; i++) {
//trace("Top level:", categoryNames*);
var pages:XMLList = navData..page.(categoryName == categoryNames*);
for (var p:int = 0; p < pages.length(); p++) {
//trace(" -> Subpage: "+ pages[p].pageName +" : "+ pages[p].type);
}
buildButtons(categoryNames*, pages.pageName);
videoList(categoryNames*, pages.content.loadUrl);
}
}
var vidSource:String;
var videoPaths:Array = new Array();
var vidCounter:int=0;
function videoList(categoryName:String, url:String):void {
switch (categoryName) {
case "Introduction" :
videoPaths.push(url);
break;
case "Our Work" :
videoPaths.push(url);
break;
case "Our Services" :
videoPaths.push(url);
break;
}
}
// Set the function for what happens when that button gets clicked
function clipClick(e:Event):void {
//outText.text=e.target.clickToPage;
switch (e.target.clickToPage) {
case "Introduction" :
if (vidPlaying=="false") {
stream_ns.close();
playNextVideo(vidSource);
} else {
playVideos(vidSource);
}
container.visible=true;
break;
//
case "Our Work" :
if (vidPlaying=="false") {
stream_ns.close();
playNextVideo(vidSource);
} else {
playVideos(vidSource);
}
container.visible=true;
break;
//
case "Our Services" :
if (vidPlaying=="false") {
stream_ns.close();
playNextVideo(vidSource);
} else {
playVideos(vidSource);
}
container.visible=true;
break;
//
}
}
function playVideos(vidSource):void {
stream_ns.close();
vidSource=String(videoPaths[vidCounter]);
trace("video currently playing :", vidSource);
outText.appendText("
"+ vidSource);
//play first video
stream_ns.play(vidSource);
}
function playNextVideo(vidSource):void {
vidSource=String(videoPaths[vidCounter]);
trace("video currently playing :", vidSource);
outText.appendText("
"+ vidSource);
//play next video
stream_ns.play(vidSource);
}
here is a partial section of the XML
<pages>
<page>
<categoryName>Introduction</categoryName>
<pageName>Animated Logo</pageName>
<type>Static</type>
<order>1-1</order>
<content>
<flashId>webriver-anilogo</flashId>
</content>
</page>
<page>
<categoryName>Introduction</categoryName>
<pageName>Welcome Video</pageName>
<type>Video</type>
<order>1-2</order>
<content>
<loadUrl>http://pegasus.dev.webriverinteractive.com/API/Resource.ashx?ResourceID=72</loadUrl>
</content>
</page>
<page>
<categoryName>Our Work</categoryName>
<pageName>We Make It So</pageName>
<type>Static</type>
<order>2-1</order>
<content>
<flashId>webriver-makeitso</flashId>
</content>
</page>
<page>
<categoryName>Our Services</categoryName>
<pageName>Application Development</pageName>
<type>Video</type>
<order>3-1</order>
<content>
<loadUrl>http://pegasus.dev.webriverinteractive.com/API/Resource.ashx?ResourceID=73</loadUrl>
</content>
</page>
//...