Home Tutorials Forums Articles Blogs Movies Library Employment Press Buy templates

Go Back   ActionScript.org Forums > ActionScript Forums Group > ActionScript 3.0

Reply
 
Thread Tools Rate Thread Display Modes
Old 02-20-2006, 05:50 AM   #1
john100
Registered User
 
Join Date: Feb 2006
Posts: 22
Default Simple htmltext control

Hi again,

I am trying to create html text into a control.
I cannot use this line below, it give error=> ecounter "<b>" expecting "/Script"
txt.htmlText = "<b>fassdfsdfdsf</b>";

however, if I use this line below(without html tag), it is fine
txt.htmlText = "fassdfsdfdsf";

any one know how to embedded html to the text/control or anything that able to produce html.

There is a tag call <mx:htmlText> => but I cannot find it in actionscript

public function initApp():void
{
var n:VBox = new VBox();
var txt:Text = new Text();
txt.html = true;
txt.htmlText = "<b>fassdfsdfdsf</b>";
n.addChild(txt);
this.addChild(n);
}
john100 is offline   Reply With Quote
Old 02-20-2006, 06:05 AM   #2
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

ActionScript Code:
_root.createTextField("_txt", 0, 0, 0, 0, 0); _txt.autoSize = true; _txt.border = true; _txt.html = true; _txt.htmlText = "<b>Hello World</b>"+" Hello World";

Works fine.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 02-20-2006, 04:41 PM   #3
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

ignore what flash gorden said, he is living the old style there
ActionScript Code:
var n:TextArea = new TextArea(); n.htmlText = "<p> kjasj</p><br/><p>more random text</p>"; this.addChild(n);

i think most of the text components have a htmlText property and using that makes it a html container by default. styling these were an issue in flex 1.5 (not as straight foreward as other components) but i have not checked this with flex 2 yet
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 02-20-2006, 04:43 PM   #4
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

notice what i did here, i used textarea, label will defnitly work as well. i would not use text on its own (you have the flex fraework already so use it!)
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 02-21-2006, 02:09 AM   #5
Tink
Addict
 
Tink's Avatar
 
Join Date: Nov 2001
Location: London
Posts: 2,128
Default

or in AS

Code:
import flash.display.TextField;
import flash.display.TextFieldAutoSize;

private function createTextField():void
{
       var myText = new TextField();
       myText.autosize = TextFieldAutoSize.LEFT;
       myText.html = true;
       myText.htmlText = "<p> kjasj</p><br/><p>more random text</p>";
       addChild( myText );
}
also Text and TextArea are all part of the flex framework. in fact Text extends Label. So Label would be the lowest level to go to create a simple field.
Tink is offline   Reply With Quote
Old 02-21-2006, 02:24 AM   #6
Flash Gordon
rather be programming
 
Flash Gordon's Avatar
 
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
Default

Quote:
Originally Posted by hangalot
ignore what flash gorden said, he is living the old style there
Oops.....Sorry I didn't see it was AS 3.0.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman
Flash Gordon is offline   Reply With Quote
Old 02-21-2006, 05:37 AM   #7
john100
Registered User
 
Join Date: Feb 2006
Posts: 22
Default Thank you every body

I found out the reason why most of the time, it prompt me "/Script" error.

When I didnot wrap the <mx:script> with "<![CDATA[". It give an error. But if I wrapped. It is fine.

However, I am still not able to display the text with this below code.
(You can try to copy paste and run it. It showing up nothing.)

Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*"  layout="absolute"   creationComplete="createTextField()">
<mx:Script>
<![CDATA[
	import flash.display.TextField;
	import flash.display.TextFieldAutoSize;	
	private function createTextField():void
	{
       var myText:TextField	 = new TextField();								    						    											       
       myText.autoSize = TextFieldAutoSize.LEFT;			       
       myText.html = true;
       myText.htmlText = "<p> kjasj</p><br/><p>more random text</p>";
	   this.addChild( myText );					       
	}
]]>						
</mx:Script>
</mx:Application>
However, if I run this code below by commenting out myText, it show the box, which means, I code it correctly, except for myText area.
You can copy paste the code and try it.
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*"  layout="absolute"   creationComplete="createTextField()">
<mx:Script>
<![CDATA[
import flash.display.TextField;
import flash.display.TextFieldAutoSize;
import mx.containers.VBox;		
private function createTextField():void
{
  var n:VBox = new VBox();
   var myText:TextField	 = new TextField();		
    						    
    n.setStyle("borderThickness", "5");		 
    n.setStyle("borderStyle", "solid");		 					    
    n.setStyle("backgroundColor", "0x5a6970");	
    n.x = 200;
	n.y = 200;
	n.width = 200;
	n.height = 200;			
			       
   //myText.autoSize = TextFieldAutoSize.LEFT;			       
   //myText.html = true;
   //myText.htmlText = "<p> kjasj</p><br/><p>more random text</p>";
   //n.addChild(myText);
   this.addChild( n );
       
}
]]>						
</mx:Script>
</mx:Application>
And thanks again for the help. I starting be able to progress. I wish Macromedia provides more simple example which able to be run. That's will be helpful. Sometimes, I didnot know, is it because of beta it is cannot be run or is it I am not coding it correctly.
john100 is offline   Reply With Quote
Old 02-21-2006, 05:05 PM   #8
john100
Registered User
 
Join Date: Feb 2006
Posts: 22
Default It is working now

In case any body needed. Need to use TextArea as suggested by hangalot.
Using text field will not working, but who knows it work in other area.

Here is the working code
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*"  layout="absolute"   creationComplete="createTextField()">
<mx:Script>
<![CDATA[
	import mx.controls.TextArea;
	private function createTextField():void
	{
       var myText:TextArea	 = new TextArea();								    						    											       		       
       myText.html = true;
       myText.htmlText = "<p> kjasj</p><br/><p>more random text</p>";
	   this.addChild( myText );					       
	}
]]>						
</mx:Script>
</mx:Application>
john100 is offline   Reply With Quote
Old 02-21-2006, 10:13 PM   #9
hangalot
lala
 
hangalot's Avatar
 
Join Date: Feb 2002
Location: on the road
Posts: 2,859
Default

its because you are appending it to a mx:Application. as tink pointed out to me the other day sprites and the like attach fine to the display tree in a canvas while when trying to attach them to a application object doesn't work. it wants something that extends the flex framework

here is a workaround i use for that though
ActionScript Code:
var p:AllTestGui = new AllTestGui(); this.allChildrenList.addChild(p);
__________________
oi poloi
http://www.memorphic.com/news/
hangalot is offline   Reply With Quote
Old 02-22-2006, 12:42 PM   #10
Tink
Addict
 
Tink's Avatar
 
Join Date: Nov 2001
Location: London
Posts: 2,128
Default

i wouldn't really use TextField with the rest of the Flex framework useless i was developing my own component.

so as hangalot mentioned presviously you'd be best using a label here.
Code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml" xmlns="*"  layout="absolute"   creationComplete="onCreationComplete()">

	<mx:Script>
		<![CDATA[
			private function onCreationComplete():void
			{
       				label.text = "<p> kjasj</p><br/><p>more random text</p>";	       
			}
		]]>						
	</mx:Script>


	</mx:Label id="label"/>
</mx:Application>

Last edited by Tink; 02-22-2006 at 12:48 PM..
Tink is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

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 Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Simple Summing With Components rpickett Components 0 10-01-2004 03:42 AM
Why does my simple actionscript make my simple tween fail? CodeNRun Animation and Effects 4 08-11-2004 01:49 PM
Why does my simple actionscript make my simple tween fail? CodeNRun Simple Stuff (Newbies) 1 07-30-2004 04:57 PM
Just... simple... text ChyChsco Simple Stuff (Newbies) 1 06-10-2004 06:40 PM
Simple. Very simple but I need help! Chucky Other Flash General Questions 2 01-11-2003 01:37 PM


All times are GMT. The time now is 11:07 AM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2009 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.