import mx.collections.ArrayCollection;
import mx.rpc.http.HTTPService;
import flash.util.trace;
import flash.net.*;
import flash.events.*;
import mx.controls.Alert;
import mx.rpc.events.ResultEvent;
//MAIN DATA SOURCE
public var rawXML:XML;
//Reference directly to a more useful node.
[Bindable]
public var configData:XML;
//Referene directly to the selected news Item.
[Bindable]
public var newsItemData:XML;
//A lot of this code may be not be needed when the next version of Flex is released. There has been "some" consideration of
//adding direct binding to XML for components.
//http://www.macromedia.com/cfusion/webforums/forum/messageview.cfm?catid=584&threadid=1084337&enterthread=y
private function start() {
//This is called from the creationComplete from the MX:Application
trace("Start");
//Creates a URL loader, configures the listerns and loads our config.xml.
var loader:URLLoader=new URLLoader();
configureListeners(loader);
var request:URLRequest= new URLRequest("config.xml")
loader.load(request);
}
private function addNewsItem() {
//Createa a new default ITEM node and adds it to the newsItem node. We then rebuild the news Item Selector.
//This is such a great way to work with XML in code!
var newItem:XML =
Default HeadlineDefault Body Text
www.evilfree.com
;
//Add to news Item Node XML
configData.news.appendChild(newItem);
rebuildNewsSelector()
}
private function removeNewsItem() {
//This deletes the selected Item.
//Make sure not all the items are deleted. The Ticker needs at least one.
if(configData.news.item.length()==1) {
Alert.show("ERROR! A news ticker without any stories is like a cloud without rain. Nobody wants it...");
return;
}
//Delete the currently selected Node
var si:int=newsItemSelector.selectedIndex
delete configData.news.item[si];
rebuildNewsSelector();
//now we pull the selection again, as the componenet will automatically update the index and accoutn for special situations like deleting the first item.
si=newsItemSelector.selectedIndex
trace(si);
newsItemData=configData.news[0].item[si];
}
private function rebuildNewsSelector() {
newsItemSelector.dataProvider=buildArray(configData.news.item.title);
}
private function buildArray(xmlList:XMLList):Array {
//takes and XML list and creates an array from it. The XML list must contain XML with only value per node... or this probably won't do what you want.
//I also created an itemNum index when building the Array...
var a:Array=[]
var numItems:int=xmlList.length();
for(var i:int=0;i