View Full Version : Adding Hyperlink to text inputed by XML? Stylesheets?
zeech26
05-28-2009, 08:45 PM
Hello, I have a site that is using XML to display text and images.
Here is the AS 2 code I am using in flash to display text:
stop();
my_xml = new XML();
my_xml.load("xml/spa_text_galleries.xml");
my_xml.onLoad = my_function;
my_xml.ignoreWhite = 1;
function my_function() {
tours_mc.tours.text = my_xml.firstChild.childNodes[0].attributes.body_name;
}
Here is a shortened example of the XML file I am using:
<?xml version="1.0" encoding= "UTF-8" ?>
<!-- Massage -->
<texts>
<text body_name="Rejuvenate your body and soul..." ></text>
</texts>
Two questions:
Can I add a hyperlink to the text in the XML to open a new page? Like you would in HTML: <a href="#" target="_blank">here:</a>
Can I style the XML with a stylesheet to create Headers, footers, etc?
I have googled the hell out of this, but my searches are coming up with a lot of almosts, but no hits.
Thanks for any help!!
zeech
Medyman
05-28-2009, 10:14 PM
Can I add a hyperlink to the text in the XML to open a new page? Like you would in HTML: <a href="#" target="_blank">here:</a>
Yes, you can. For this to work, you have to pass the string value from the XML in as HTML and the text field in question has to be configured to allow HTML input. You do this through two short lines of AS. If your text field has an instance name of tf, your code might look like this:
tf.html = true;
tf.htmlText = "This is a <a href='http://google.com'>link</a>.";
Can I style the XML with a stylesheet to create Headers, footers, etc?
Why do you want to do that? The XML usually isn't public facing and doesn't need styling. Technically, you can style XML with CSS (http://www.w3.org/TR/CSS2/intro.html#xml-tutorial) but I'm not sure if any browsers support it.
zeech26
05-28-2009, 10:43 PM
Thanks Medyman, I am still a bit confused though:
"Yes, you can. For this to work, you have to pass the string value from the XML in as HTML and the text field in question has to be configured to allow HTML input. You do this through two short lines of AS. If your text field has an instance name of tf, your code might look like this:"
Code:
tf.html = true;
tf.htmlText = "This is a <a href='http://google.com'>link</a>.";
I am confused, this is AS that goes where? About this code that i have placed:
stop();
my_xml = new XML();
my_xml.load("xml/info_text_galleries.xml");
my_xml.onLoad = my_function;
my_xml.ignoreWhite = 1;
function my_function() {
raft_mc.raft.text = my_xml.firstChild.childNodes[3].attributes.body_name;
}
See site (inprogress here) to see why I want to style the XML
Click on any menu and take a look at the text, it is ugly!
http://www.contentx.com/MINAHASA_WEB
Can I style the XML with a stylesheet to create Headers, footers, etc?
Why do you want to do that? The XML usually isn't public facing and doesn't need styling. Technically, you can style XML with CSS but I'm not sure if any browsers support it.
Medyman
05-29-2009, 02:40 AM
You would need to change your my_function to this:
function my_function() {
raft_mc.raft.html = true;
raft_mc.raft.htmlText = my_xml.firstChild.childNodes[3].attributes.body_name;
}
RE: Styling XML
I misunderstood you. You don't want to style the XML, you want to style the output. The easiest way to do this would be to style the text area and/or component directly using the properties panel. It is also possible to attach a stylesheet to a textarea using the TextField class. I suggest you dig into the livedocs (http://livedocs.adobe.com/flash/8/main/00002714.html#453576) for some examples.
zeech26
06-01-2009, 05:06 PM
Medyman,
one quick thing,
How do I add the code into the XML document for it to appear as a URL?
I tried this:
<url>http://www.google.com</url>
and that did not work, it makes my XML undefined
help!
thanks mate,
zeech
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.