Flash CS3 - Flash CS4

Free tutorials and scripts for all.
Actionscript 3.0

HTML text in XML

This is a discussion on HTML text in XML within the Tutorials forums, part of the English Forums category; This article is to illustrate how to use HTML text inside an XML file so that Flash can load the ...


Go Back   Forum Flash CS3 Flash CS4 > English Forums > Tutorials

Register FAQ Members List Calendar Search Today's Posts Mark Forums Read
  5 links from elsewhere to this Post. Click to view. #1 (permalink)  
Old 29-09-07, 10:08
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,446
Rep Power: 6
Flep is on a distinguished road
HTML text in XML

This article is to illustrate how to use HTML text inside an XML file so that Flash can load the XML and render the text as HTML.
The introduction of HTML strings in an XML file is done via the XML CDATA tag.
The Flash"s parser does not interpret the XML tag Character Data (CDATA). This way, we can retrieve with precision the HTML text format.

Let"s see how"

I create a FLA and save it as "xml_e_html.fla".
I create a dynamic multiline text field and I call it "test_txt".
Now, I create 2 single line text fields to insert the font in the SWF and as we will need Bold and Italic, the text fields will be 2.
See article "Embed fonts in a SWF
This way, I will have 3 text fields as follow:
- the main "test_txt" (multiline) to which I will insert the sets of character I prefer
- a dynamic text field (single line) with the option Bold turned on to which I will insert the same sets of characters as "test_txt".
- a dynamic text field (single line) with the option Italic turned on to which I will insert the same sets of characters as "test_txt".
As from now, I am sure that all the fonts needed will be included in the SWF when published.
I drag on stage a scrollBar component from the components window, open the parameters window of the component and in the option ScrollTargetName , I insert the instance name of the multiline text field (test_txt).
I now create a Document Class, an AS file saved as "Main.as", which will load the XML file as follow:
Code:
package
{
	import flash.display.Loader;
	import flash.display.MovieClip;
	import flash.text.TextField;
	import flash.events.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import flash.xml.*;
	
	public class Main extends MovieClip
	{
		public function Main()
		{
			this.loadXML();
		}
		private function loadXML():void
		{
			var loader:URLLoader=new URLLoader();
			loader.addEventListener(Event.COMPLETE,completeHandler);
		
			var request:URLRequest=new URLRequest('testo.xml');
			try 
			{
				loader.load(request);
			} 
			catch(error:Error) 
			{
				trace('Unable to load requested document.');
			}
		}
		private function completeHandler(event:Event):void
		{
			var loader:URLLoader=URLLoader(event.target);
			var result:XML=new XML(loader.data);
			var myXML:XMLDocument=new XMLDocument();
			myXML.ignoreWhite=true;
			myXML.parseXML(result.toXMLString());
			var node:XMLNode=myXML.firstChild;
			test_txt.htmlText=node.firstChild.firstChild.nodeValue;
		}
	}
}
Here is the result:







Click here to see the XML file.

See you next"

__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !

Last edited by Flep; 28-08-08 at 06:21..
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #2 (permalink)  
Old 04-05-08, 01:18
johnrlhunter
 
Join Date: May 2008
Location: Salisbury, England
Posts: 2
Rep Power: 0
johnhunter is on a distinguished road
Re: HTML text in XML

Hi thanks for posting your tutorial. I love this site!

I am building my music flash pages, where I intend (once I figure out how to have figured out why I cant creat buttons in coverflow) to have my mp3 player display my lyrics as well as the song title. I can get the plain text displaying but if I put in any

tags it falls over? Could I get xml to point to a html file and do it that way?

Cheers
John

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #3 (permalink)  
Old 06-08-08, 19:29
Junior Member
 
Join Date: Aug 2008
Posts: 3
Rep Power: 0
jcaldwell is on a distinguished road
Re: HTML text in XML

I tried replicating your code and got this error

[object URLLoader]
TypeError: Error #2007: Parameter text must be non-null.
at flash.text::TextField/set htmlText()
at Main/completeHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

Can you help me out with this? Thanks in advance!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #4 (permalink)  
Old 06-08-08, 19:54
Junior Member
 
Join Date: Aug 2008
Posts: 3
Rep Power: 0
jcaldwell is on a distinguished road
Re: HTML text in XML

I figured it out...
I forgot to include the < ! [ CDATA [ tags in my XML.
Works great now!
Thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #5 (permalink)  
Old 06-08-08, 20:53
Junior Member
 
Join Date: Aug 2008
Posts: 3
Rep Power: 0
jcaldwell is on a distinguished road
Re: HTML text in XML

could you tell me how to apply an external css file to this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Flash Multi Gallery
  #6 (permalink)  
Old 25-09-08, 10:59
Junior Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
Dammernung is on a distinguished road
Re: HTML text in XML

i know this can sound stupid but i've just started doing this things in flash and when i try to run ctrl+enter to view the final output it give me an error 1120: Access of undefined property test_txt.
i know the answer should be right under my nose but can't find it. can you please point towards it?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #7 (permalink)  
Old 26-09-08, 05:56
Onsitus's Avatar
CSS.FlepStudio.org
 
Join Date: Jul 2007
Location: Nettuno Beach
Posts: 973
Rep Power: 2
Onsitus is on a distinguished road
Re: HTML text in XML

Quote:
Originally Posted by Dammernung View Post
i know this can sound stupid but i've just started doing this things in flash and when i try to run ctrl+enter to view the final output it give me an error 1120: Access of undefined property test_txt.
i know the answer should be right under my nose but can't find it. can you please point towards it?
Hi, did you give the right instance name to the text field???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #8 (permalink)  
Old 26-09-08, 08:59
Junior Member
 
Join Date: Sep 2008
Posts: 2
Rep Power: 0
Dammernung is on a distinguished road
Re: HTML text in XML

yes i did that... i worked in flash a bit prior to this and did some coding but never this one and obsiusly couldn't find something to help me on the internet :(
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #9 (permalink)  
Old 04-11-08, 20:46
Junior Member
 
Join Date: Nov 2008
Posts: 2
Rep Power: 0
ottokardomma is on a distinguished road
Re: HTML text in XML

hi, i tried this too but i´ve got the same error like dammernung 1120: Access of undefined property test_txt. i have given the right instance for the text field... is there anyone who can post the running fla and as files - thanks!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

  #10 (permalink)  
Old 11-11-08, 17:27
Administrator
 
Join Date: Jul 2007
Location: Cesena
Posts: 4,446
Rep Power: 6
Flep is on a distinguished road
Re: HTML text in XML

Hi,
here they are:
Attached Files
File Type: zip html_xml.zip (530.9 KB, 7 views)

__________________

 


I recommend: Essential Actionscript 3.0

- Non rispondo ai messaggi privati con domande tecniche. Apri una discussione sul forum !
- I do not reply technicians pvt messages. Open a thread !
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote

Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump

Similar Threads

Thread Thread Starter Forum Replies Last Post
Actionscript 3 Papervision e input text enricoB Actionscript 3.0 avanzato 0 01-09-08 04:52
Actionscript 3 Text Field in AS3 sututuyet advanced Actionscript 3.0 0 27-06-08 03:59
why can't i post html in my flash text???? roxylady HELP free utilities 3 26-04-08 02:51
text fields generated or not? gwulfwud Actionscript 3.0 newbies 2 18-11-07 23:22
Html in text area Mushroom Flash CS3 generale 2 05-09-07 17:51


All times are GMT. The time now is 23:35.


Powered by vBulletin versione 3.7.4
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0 RC4
Forum SiteMap


FlepStudio
by Filippo Lughi
P.IVA 03605860406