Skip to main content
Kristtee
Known Participant
May 23, 2010
Answered

Dynamic data Integration trouble

  • May 23, 2010
  • 2 replies
  • 668 views

Hi There

I am trying to load, read, and get data from xml into a listbox, textarea, and a dynamic textField. I was able to get it all right but the dynamic textField data does not update as i select item in the listbox. Another thing is thing is when I click on dynamic textfield it should open page in browser - how can i do that?
Please help
Appreciate your time.
Thanks
Krish
--------------------
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://rssfeeds.tv.adobe.com/learn-flash-professional-cs4.xml"));
//lb is ListBox component in stage
lb.addEventListener(Event.CHANGE, itemChange);

function itemChange(e:Event):void
{
ta.text = lb.selectedItem.data;//ta is TextArea in stage
}

function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
parseData(xmlData);
}
function parseData(loadedData:XML):void {
//trace(loadedData.channel.item);
//trace(loadedData.channel.item.length());
var titleList:XMLList=loadedData.channel.item;
for (var i:uint = 0; i<titleList.length(); i++) {
lb.addItem({label:titleList.title.text(), data:titleList.description.text()});
uri.text = titleList.link.text();
//uri is dynamic TextField on stage
}
}
--------------------------------
Fla file is http://www.naturecareasia.com/test/learnCS4.flv.fla
-----------------------------

This topic has been closed for replies.
Correct answer Ned Murphy

You don't do anything to store the data for the link, nor to update the textfield with it when a selection is made, nor do you add a hyperlink for it to the textfield.

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var uriLinks:Array = new Array();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://rssfeeds.tv.adobe.com/learn-flash-professional-cs4.xml"));
//lb is ListBox component in stage
lb.addEventListener(Event.CHANGE, itemChange);

function itemChange(e:Event):void
{
ta.text = lb.selectedItem.data;//ta is TextArea in stage
uri.htmlText = "<a href='"+uriLinks[lb.selectedIndex]+"' target='_blank'>"+uriLinks[lb.selectedIndex]+"</a>";
}

function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
parseData(xmlData);
}
function parseData(loadedData:XML):void {
//trace(loadedData.channel.item);
//trace(loadedData.channel.item.length());
var titleList:XMLList=loadedData.channel.item;
for (var i:uint = 0; i<titleList.length(); i++) {
lb.addItem({label:titleList.title.text(), data:titleList.description.text()});
uriLinks.push(titleList.link.text());

//uri.text = titleList.link.text();
//uri is dynamic TextField on stage
}
}

2 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
May 23, 2010

You don't do anything to store the data for the link, nor to update the textfield with it when a selection is made, nor do you add a hyperlink for it to the textfield.

var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var uriLinks:Array = new Array();

xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("http://rssfeeds.tv.adobe.com/learn-flash-professional-cs4.xml"));
//lb is ListBox component in stage
lb.addEventListener(Event.CHANGE, itemChange);

function itemChange(e:Event):void
{
ta.text = lb.selectedItem.data;//ta is TextArea in stage
uri.htmlText = "<a href='"+uriLinks[lb.selectedIndex]+"' target='_blank'>"+uriLinks[lb.selectedIndex]+"</a>";
}

function LoadXML(e:Event):void {
xmlData=new XML(e.target.data);
parseData(xmlData);
}
function parseData(loadedData:XML):void {
//trace(loadedData.channel.item);
//trace(loadedData.channel.item.length());
var titleList:XMLList=loadedData.channel.item;
for (var i:uint = 0; i<titleList.length(); i++) {
lb.addItem({label:titleList.title.text(), data:titleList.description.text()});
uriLinks.push(titleList.link.text());

//uri.text = titleList.link.text();
//uri is dynamic TextField on stage
}
}

Kristtee
KristteeAuthor
Known Participant
May 24, 2010

Hello NedMurphy

Many many  thanks. You rock. Appreciate your time and help.

Krish

Ned Murphy
Legend
May 24, 2010

You're welcome Krish

May 23, 2010

Hmm, are you sure your text field is dynamic, font is embedded, and you have given it an instance name of ta? I copy pasted your code directly, put a list box and a text field on stage with instance names of lb and ta and it worked just fine. Put a trace in your change handler to help debug... but I think it's got to be something with your field as the code does work.

As for opening in a browser... just use a navigateToURL in your change handler.