PDA

View Full Version : can't use <b> in xml-file.



kathari
May 12th, 2009, 09:41 AM
Hi all,
I am trying to format some content in an xml-file so that some "headlines" get bold. However using <b> doesn't change anything. Actually it doesnt even read as html, I see the whole tag as part of the text. <strong> doesn't work either.

The text-field in Flash is set to Arial and I haven't ticked the bold-possibility. If I do, then everything becomes bold and I can't take it away reversing the bold-tags when needed.

I was using <![CDATA[Here is some text]] but had to take it away and now only use the xml-tag+ <html>. Then I can at least format with <u> and the size with <font size="16">.

Anyone knows what I am doing wrong? :puzzle:

kunjan
May 19th, 2009, 08:30 AM
Hello,

if you want to apply html formation via xml file for your textbox then you have to assign text to "htmlText" text property not to "text" property

like txtnew.htmlText = some variable

get back to me if you have any query

Regards,
Kunjan.

kathari
May 19th, 2009, 08:47 AM
Hi,
thanks for replying. I had kind of given up..
I have of course applied htmlText to the text-box (my_txt.htmlText = thecorrectxmlNode; ) and I can apply <u> and <a> as a tag for example. It seems to me that the problem is that I have linked and exported the typeface (which in this case is Arial) without bold ticked in the Linkage dialog-box.
But what do I do if I actually want to make some text bold in the xml-file?:puzzle:

kathari
May 19th, 2009, 12:15 PM
Here is a stripped FLA with the xml-file.
In order for it to work published you'll need to put a picture called "page-one_1.jpg" in a folder in the same location, called PICS.

kunjan
May 20th, 2009, 03:40 AM
Hello,

you need to change two thing for rendering text as a html in your textbox in as2

1. click on button "Render text as HTML" (with sign "<>") in property window of textbox as show in image
2. give the variable name in property of textbox as show in image(here variable name is fotografvar)

and in code instead of assigning value to text box like

fotograf.text = photographer.firstChild.nodeValue;

you should assign value to variable
fotografvar = photographer.firstChild.nodeValue;(fotografvar name of variable )

I am attaching image(which guide you to giving variable name & active "Render text as HTML" button in property window), xml & fla file with this

I have also make one samll change in xml file put cdata with values

get back to me if you have query

Regards,
kunjan.

kathari
May 20th, 2009, 07:07 AM
Thanks for the try Kunjan but it doesn't change anything at all. I still can't display the text that I want (which is another text than the one you tweaked) as bold or italic.

What's weird though is that when I change the biography-text as you did to the header (fotografvar), it doesn't work with <![CDATA[ ]]>. It ends up displaying all the tags as text. And your changes don't do that..:m:

Navee
May 21st, 2009, 03:44 AM
Hello Mate

I format text from XML religiously and <![CDATA[]]> is the way to go. It will not display the tags and use the HTML assigned formats if you follow the steps below.

I'm sure you have everything as far as render to HTML setup and font symbols embedded right?

Just use HTML tags from that point...here are some of the things I do often:

<tagname><![CDATA[<b>This is bold text</b>]]></tagname>

<tagname><![CDATA[<a href='http://www.somewebsite.com'><img src='http://www.somewebsite.com/images/header.jpg' /></a>]]></tagname>

<tagname><![CDATA[<b><font size='30'>This is huge</font> and bold but small text here<font color='00FF00'>and some color</font></b>]]></tagname>

Basically html tags as usual. Of course you can also create it on the flash side, but there's more control over not having to open the flash document all the time if using HMTL tags inside of XML CDATA tags for sure.

On the flash side:

text_field.htmlText = ""+yourvariable+"";

YOU MUST APPLY/CONCAT THE BLANK QUOTES! Simply dropping in the variable as the value to an dynamic htmlText field WILL NOT do!!! As mentioned I do this ALL the time.

Otherwise if you want to take the flash route:

text_field.htmlText = "<b>"+yourchildnode_var+"<b>";

text_field.htmlText = "<a href='"+yourchildnode_var+"' target='_blank'><u>"+yourchildnode_var+"</u></a>";

DO NOTE the single quotes are used for assigning HTML attribute values because double quotes are used for strings in flash. If you use the <a> or <img> and assign a variable instead of hardcoding a valuse: wrap the double qoutes inside of the single quotes like above. Also if you use the HTML tags in XML instead (preferred) use single quotes in the XML and remember that you always use doube quotes plus conact (unless hardcoding the value) when using the htmlText property if you want it to display as intended (even if they are blank--use them!!!)

Pursuant to the <a><u> example in actionscript above, if your xml node was:
<sites><![CDATA[www.somewebsite.com]]></sites>

The output in the text_field would be: www . somewebsite . com with underline because of the <u> tag of course. I spaced it out here because it turns into a hotlink in this message box. But it reads just as the value in the XML element (and selectable due to the anchor!) The reason I recommend performing the HTML task in XML (other than the obvious benefit of dynamic editing without need to open the fla) is that you also can add the other attributes like target=''...otherwise selecting the link would open the targeted link as _self and lose focus from the flash site rather opening in a new window)

THE POINT IS: you MUST use quotes and concat the variable within...does not matter it can be inside a loop text_field.htmlText = ""+arr_list[i]+"\n"; or "<br />";

If you want to dive in deeper create a CSS object, define a stylesheet and go to town in the XML CDATA tag as if you were styling an HTML page. Flash will assign the CSS object to the desired variable(s) etc. Nonetheless, this can be done because I use these methods on nearly every project I develop.

Try it...and your days of problems will be solved :)


Cheers

Navee
May 21st, 2009, 05:48 AM
I changed your XML file to this and the output was successful!



<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<portfolio>
<namntext><![CDATA[<b><font size='60'>NAME MYNAME</font></b>]]></namntext>
<menu>
<menuitem><![CDATA[<b>PORTFOLIO 1</b>]]></menuitem>
<menuitem><![CDATA[<b>PORTFOLIO 2</b>]]></menuitem>
<menuitem><![CDATA[<b>PORTFOLIO 3</b>]]></menuitem>
<menuitem><![CDATA[<b>BIOGRAPHY</b>]]></menuitem>
</menu>
<firstPicture>PICS/page-one_1.jpg</firstPicture>
<address><![CDATA[<b><font color='#AA2F11'>NAME MYNAME</font></b>
CHAMPS ELYSEES 2
75009, PARIS, FRANCE

+33 (0)1 23 45 67 89
+33 (0)1 23 45 67 89]]></address>

<email><![CDATA[<a href='mailto:info@mailaddress.com'><u><font color='#0000FF'>info@mailaddress.com</font></u></a>]]></email>
<info><![CDATA[<b><font size='16'>BIOGRAPHY</font></b>
This is supposed to be the bio-text.
<u>HEADER</u> that I want to have in <b>bold.</b>
I can't make it a <h3>header 3</h3> either, it doesn't change anything unless I change the <font size='30'>text size</font> because flash does not support Headers unless you format a CSS object and use a stylesheet instead.]]></info>
</portfolio>


You know you actionscript code. I added a few changes. I.e added a loop and nodes variable to reduce all the nextsibling lines and a loop to populate your menu buttons. I discovered through troubleshooting your file that the nextsibling routines you build caused the html-enabled fields not to show any changes and output whatever was stored in the xml. Try to change your actionscript in this one section only to the following and your HTML will perform as you intend.


stop();
//New: added to show how the XML font size is changing the text in this field...
fotograf.autoSize = true;

function loadXML0(loaded) {
if (loaded) {
//New: added to shorten the method and test why certian fields are not respoding to HTML tags.
var nodes = this.firstChild.childNodes;

var photographer = this.firstChild.firstChild;
var menu = photographer.nextSibling;
var firstpic = menu.nextSibling;
loadFirst0(firstpic.firstChild);

fotograf.htmlText = ""+nodes[0].firstChild.nodeValue+"";

// New: added to reduce the menu1,2,3,4 thing.
// "menu" + (i+1) because you started your menu with 1
// but the node in the XML for the menu labels start with 0
for(var i=0; i<nodes.length; i++) {
_level0["menu"+(i+1)].menuTitle.htmlText = ""+nodes[1].childNodes[i].firstChild.nodeValue+"";
}
// New: Instead of all the nextsiblings just call the index number
// index could be set to a variable and dynamically changed etc.
infoMC.info_txt.htmlText = ""+nodes[5].firstChild.nodeValue+"";
infoMC.adress_txt.htmlText = ""+nodes[3].firstChild.nodeValue+"";
infoMC.epostMC.epost_txt.htmlText = ""+nodes[4].firstChild.nodeValue+"";
} else {
content = "file not loaded!";
}
}
var xmlData:XML = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML0;
xmlData.load("portfolio.xml");


Cheers

kathari
May 21st, 2009, 06:00 AM
Thanks!!!!!!!!!
Will try this as soon as I can.:hugegrin:

kathari
May 26th, 2009, 05:22 AM
Hi again Navee,
I have made all your changes and everything works fine in the sense that I get no error messages and all text shows in the places they should. In other words, I transported your changes to my fla without errors as far as I can understand...
But, I still can't make the text that I want bold.. The tags <u>, <a href> <font> all work fine but not <b> and <i>.

I am using simple Arial, have exported it and linked it, If I tick the options italic and bold, everything becomes bold and italic and I can't change that either.

So, what is wrong? And how come you could tweak my stripped file? Unless you changed it, I didn't make any changes when I stripped it, neither in the linkage and export nor in the actual textfields.:upset:

Navee
June 11th, 2009, 02:15 PM
Kathari attached are the changes made according to the post with working formats (including the XML) ...see if this works for you.

Another thing worth mentioning: When you use html formatting in XML pursuant to tag attributes <font size=, color=, <a href=, <img src=, etc. Use single quotes instead of double quotes.

I.e. <font size='16' color='#0000FF'..., <a href='http://www.google.com'..., <img src='images/pic1.jpg' width='100' height='50' alt='vacation picture'..., etc.

Navee