| Home | Tutorials | Forums | Articles | Blogs | Movies | Library | Employment | Press | Buy templates |
|
|
#1 |
|
Registered User
Join Date: Feb 2006
Posts: 22
|
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); } |
|
|
|
|
|
#2 |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
ActionScript Code:
Works fine.
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
|
|
|
|
|
#3 |
|
lala
Join Date: Feb 2002
Location: on the road
Posts: 2,859
|
ignore what flash gorden said, he is living the old style there
![]() ActionScript Code:
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 |
|
|
|
|
|
#4 |
|
lala
Join Date: Feb 2002
Location: on the road
Posts: 2,859
|
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!)
|
|
|
|
|
|
#5 |
|
Addict
Join Date: Nov 2001
Location: London
Posts: 2,128
|
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 );
}
|
|
|
|
|
|
#6 | |
|
rather be programming
Join Date: Feb 2005
Location: City of Angels
Posts: 10,000
|
Quote:
__________________
I'm old enough to know better and young enough to do it anyway. -- maskedman |
|
|
|
|
|
|
#7 |
|
Registered User
Join Date: Feb 2006
Posts: 22
|
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>
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>
|
|
|
|
|
|
#8 |
|
Registered User
Join Date: Feb 2006
Posts: 22
|
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>
|
|
|
|
|
|
#9 |
|
lala
Join Date: Feb 2002
Location: on the road
Posts: 2,859
|
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:
|
|
|
|
|
|
#10 |
|
Addict
Join Date: Nov 2001
Location: London
Posts: 2,128
|
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.. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
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 |