Hello. I have a widget that pulls in images via an xml file and it works
great. However, I want to convert this widget into one that pulls in a URL
instead of the image and is clickable as a hyperlink. I want to change my
slideshow into a news scroller.
Can anyone show me a tutorial that will help? I can pull in the new xml just
fine but making the text a hyperlink is where I'm stuck.
Noelbaland - 22 Jul 2008 05:03 GMT
Hello,
Make your textfield read HTML by clicking on the Render text as HTML option in
the Properties panel.
Concatenate the variable that holds the URL from your XML file to a string
that will be read into the textfield as HTML
// Lets say that your one of the nodes in your XML file looks like this
<link title="Google" url="http://www.google.com" />
// Then you retrieve the url and title attributes like this
var rootNode = xmlObj.firstChild.childNodes;
var linkURL = rootNode.attributes.url;
var linkTitle = rootNode.attributes.title;
// Concatenate the string with HTML tags
var link:String = "<a href="+linkURL+">"+linkTitle+"</a>";
// Feed it to your textfield using the htmlText method
myTextField.htmlText = link;
Hope that helps
idesdema - 22 Jul 2008 15:01 GMT
Ok cool. Now I have it working but am stuck on one last detail. I can figure
out how to get my title and url to work but I want to include a date. I have
the date in the xml but can't seem to pull it in. What I have right now is a
band-aid solution but I want to do it the right way. Here is my current code...
XML <moreovernews>
<cfoutput>
<article id ="#XMLFormat(id)#">
<url>#XMLFormat(news_URL)#</url>
<headline_text>#XMLFormat(news_title)# - #XMLFormat(news_date)#</headline_text>
<source>Rivals</source>
<media_type>text</media_type>
<cluster>News</cluster>
<harvest_time>#XMLFormat(news_date)#</harvest_time>
</article>
</moreovernews>
Flash
content_feed_display += "<p><font color=\"#041947\" face=\"verdana\"
size=\"+2\"><a href=\""+url+"\" target=\"_new\">"+ headline_text
+"</a></font><br><br></p>";
So you can see that I am pulling in headline_text and it displays fine.
However in my XML I had to combine two variables to get it to show the date as
well as the headline (title). What I want to do is stop combining the vars in
XML which is no problem and then show the harvest_time in the Flash code.
Can you help?
Thanks
Andy
Noelbaland - 23 Jul 2008 02:01 GMT
Hello,
Well done! There is a bit of an error in this section of your code.
content_feed_display += "<p><font color=\"#041947\" face=\"verdana\"
size=\"+2\"><a href=\""+url+"\" target=\"_new\">"+ headline_text +[u]"</a> "+
[B]harvest_time[/B] +"</font><br><br></p>";[/u]
Should be
"</a>[B]"+harvest_time+"[/B]</font><br><br></p>";
That should fix that up. Just an after thought, but you might want to look at
using stylesheets for your textfields. That way you don't have to declare
inline styles in your string. The Flash help is the best place to read about
that.
idesdema - 23 Jul 2008 04:19 GMT
I looked at CSS but I am using Flash 5 and I can't get it to work. That would
be ideal.
For now I'm ok with this approach. However, I tried your solution and it
pulled in the headline_text but not the harvest_time. Any ideas?
I must be close or else it would have not worked at all.
Noelbaland - 23 Jul 2008 08:07 GMT
Can you post the portion of your Actionscript that loads the XML file and seperates(parses) the nodes? I just want to see how the child elements are being pulled out. Thanks.
idesdema - 23 Jul 2008 15:24 GMT
function convertXML() {
if(this.loaded) {
content_feed_display = "Data loaded.";
}
mainTag = new XML;
elementTag = new XML;
articleList = new Array;
elementList = new Array;
//first get a handle on the first actual element in the document.
//note we skip to the nextSibling element, since the first element
//is a document definition tag.
mainTag = this.firstChild.nextSibling;
//make sure we have the right parent tag. Do this by looking at the nodeName
property
//for this object. This will correspond exactly to the <nodeName>, where
nodeName is replaced
//with the name of your xml tag
if(mainTag.nodeName.toLowerCase() == "moreovernews") {
//if we have a match, we collect all of the articles beneath it as an array
of xml objects
articleList = mainTag.childNodes;
//now we loop over all the articles and look for the tags we are looking
for...
content_feed_display = "";
for(i=0;i<=articleList.length;i++){
//initialize a couple of variables to hold xml data we want displayed
document_url = "";
headline_text = "";
if(articleList[i].nodeName.toLowerCase() == "article") {
//we get the child node array beneath the articles, aka the meat and
potatoes we are after
elementList = articleList[i].childNodes;
//and loop through that looking for the data we need
for(j=0;j<=elementList.length;j++) {
elementTag = elementList[j];
elementType = elementTag.nodeName.toLowerCase();
if(elementType == "headline_text"){
headline_text = elementTag.firstChild.nodeValue;
} else {
if(elementType == "url"){
url = elementTag.firstChild.nodeValue;
}
}
}
content_feed_display += "<p><font color=\"#0C5039\" face=\"verdana\"
size=\"+2\"><a href=\""+url+"\" target=\"_new\">"+ headline_text
+"</a>[B]"+harvest_time+"[/B]</</font><br><br></p>";
}
}
}
}
Noelbaland - 24 Jul 2008 02:00 GMT
Hi,
Ahhh - my suspicions were correct!. You hadn't declared and assigned
anything to the harvest_time variable in Flash. The headline_text and url
variables were declared as string objects. I think this will work now.
Find this section in your code
if(elementType == "headline_text"){
headline_text = elementTag.firstChild.nodeValue;
} else {
if(elementType == "url"){
url = elementTag.firstChild.nodeValue;
}
and add this under it
if(elementType == "harvest_time"){
harvest_time = elementTag.firstChild.nodeValue;
}
Now you can now remove the date variable from this node.
<headline_text>#XMLFormat(news_title)# - #XMLFormat(news_date)#</headline_text>
Just out of curiosity, are you using this variable anywhere else in your
script?
document_url = "";
If not, then you should use that variable instead of the url variable your
using in the code. Flash actually has the url variable built-in as one of the
methods for the TextField object (e.g TextField.url()). You might want to
change to avoid any conflicts.
So then you would change it here
if(elementType == "url"){
document_url = elementTag.firstChild.nodeValue;
}
and here
content_feed_display += "<p>...<a href=\""+document_url+"\"
target=\"_new\">"...
Hope all goes good
idesdema - 24 Jul 2008 04:53 GMT
That's the solution! Thank you. I don't know why I missed that... oh well. I
agree on the usage of url too. I'll change that up. Now I'm good to go.
Perhaps you can help me with my newest issue... trying to make a video widget
using Flash MX. :) Do you think it's possible?