Problem With The Multiline
I have problem with the multiline. The problem is that I have put multiline to true, but the text is still on one line?Please help me!!! Code: _root.createTextField("start_txt",300,300,50,400,200); start_txt.text = start_info; start_txt.border = true; myStart = new TextFormat(); myStart.color = 0xFFFFFF; myStart.font = "arial"; myStart.multiline = true; myStart.type = "dynamic"; start_txt.setTextFormat(myStart);
KirupaForum > Flash > ActionScript 1.0/2.0
Posted on: 01-18-2007, 05:56 PM
View Complete Forum Thread with Replies
See Related Forum Messages: Follow the Links Below to View Complete Thread
Multiline
How can I set multiline with a textfield by using AS?
I type below but it is sigle line as before.
Code:
_root.createEmptyMovieClip("newMC", 1);
with (_root.newMC) {
createTextField("character", 2, 0, 0, 100, 50);
character.multiline = true;
character.text = "djkfldlkdsflkdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdalfjdklshfjdjfkl";
}
Multiline
Hi all,
Is there a way to restrict the text input multiline?
I would like to say that you can only use up to 15 lines.
Thanks for your help.
Multiline From Xml
here's an odd one
I want to add miltiline text from an xml tag but as soon as I put it to flash, the /n and /t just don't work, how can I go around this ?
Xml Multiline?
hi
i have dynamic text boxes that retrieve text information from an xml file. Everything works great except that it doesnt seem to understand that there are line breaks in the xml code:
<body><![CDATA[text <br>goes<br />here]]></body>
i have MULTILINE and RENDER AS HTML on on all text boxes and i have also embedded the fonts to enable masking of the text boxes
help please, im using AS2
Or
Or Both For Multiline Textfield?
when using a variable to fill a multiline text field, I am using
or
for the line breaks.
I'm on a PC and it interprets them both as line breaks (so that you go down two lines if using both) but I seem to remember that a Mac needs both of these escape codes to create a single line break.
I don't have access to a Mac at the moment - could someone please try it out? Or does someone know how this works?
thanks in advance - n.
Multiline Var Loading
Is it possible to load multiline variables with LoadVariables; if yes, what's the form?
Thanks
Multiline Text
I would like to create text via actionScript, but if the text has more than one line, and I can't do it...
If I use the textTool to create text (an empty box) and name it myText, and choose multiline in the property inspector, I can do it...:
_root.myText.text = "how to create multiline text?"
works just fine...
but if I do this:
_root.createTextField("myText", xPos, yPos, w, h);
_root.myText.text = "how to create multiline text?"
_root.myText.multiline = true;
it doesn't work...
what am I doing wrong?
Multiline Listbox
is this possible. can you get more than one line per option in a listbox? if so how?
Multiline TextBox
I would like to know how to go the last line of a multiline textbox without using the SCROLL
Multiline Problem?
I have a dynamic text box and have set the following so the text written to it will break to a second line if need be.:
textBox_txt.multiline = true;
textBox_txt.wordWrap = true;
On the Mac it's fine however it doesn't break on a PC.
Any suggestions?
Multiline Array
I have created a group of buttons used in turn to create an array. It works fine, but what I can't figure out how to do is to get the items of the array to print on individual lines like:
Milk
Butter
Bread
rather than on one line separated by commas like:
Milk,Butter,Bread
How do I do this?
Also, is there a way to specify line spacing between each item once they've been placed on individual lines?
Here is the code that I have so far ...
var shopList:Array=new Array();
var i:Number=-1;
milk_btn.onRelease=function() {
++i;
shopList[i]="Milk";
}
butter_btn.onRelease=function() {
++i;
shopList[i]="Butter";
}
bread_btn.onRelease=function() {
++i;
shopList[i]="Bread";
}
enter_btn.onRelease=function() {
items_txt.text=shopList;
}
Thanks!
Multiline Concatenation
hi guys,
i was wondering if you can add on to a string in a new line, like in php it would be:
Code:
$a = "Hello ";
$a .= "World!";
i know i could do it in flash as
Code:
a="hello";
b="world";
c=a+b;
but i want to add to a string each time in a loop so it would ideally be something like:
Code:
a="blah blah blah"
for (i=0; i<=30; i++) {
a .="blah"+i
}
thanks guys,
[F8] WordWrap Vs MultiLine
Code:
function makeTxBox() {
holder = box._parent;
var txField:TextField = holder.createTextField("txField", 5, 0, 0, box._width,box._height);
txField._x = box._x;
txField._y = box._y;
txField._width = box._width;
txField._height = box._height;
txField.selectable = false;
txField.setNewTextFormat(txStyle);
txField.multiline = true;
txField.wordWrap = true;
txField.text = entryText;
init();
}
hopefully that is all you need to help. Essentially, each empty mc on my stage has a txField and a box (for background) inside. The txField rests above the box. The text is loading fine, positions look great...but the text is not wrapping....or multilining (if there is a diffrerence, that explanation could be icing)!
Multiline In Text Box?
hi guys!
i have a dynamic text box called "myTextBox"
in my button i have this:
_root.myTextBox.text = "this is a line";
what im wanting to be able to put new lines in like when you press enter when writing text.
so the result would be somthing like this:
-----------
this is line 1
this is line 2
this is line 4
etc
------------
how do i go about this?
thanks
Help With Multiline Tabstops
Hello all,
Is there a way to have multiline columns within a textfield? I have the following code:
Code:
// Create a new text field to hold text. NOTE the UI scrollbar must be on the second frame
// becasue the textfield created here must first be created before the uibar instance
this.createTextField("table_txt", 99, -26.1, -13, 345, 166.5);
table_txt.multiline = true;
table_txt.html = true;
table_txt.wordWrap = true;
// Creates column headers, formatted in bold, separated by tabs.
var rowHeaders:String = "";
// Creates rows with data.
var row_1:String = "<FONT FACE ='Verdana' SIZE ='12'><b>BSI </b> Gloves and eye protection</FONT>";
var row_2:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Scene Saftey</b> Scene is safe</FONT>";
var row_3:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Resources</b> 3 person aid crew, ALS crew added if needed</FONT>";
var row_4:String = "<b>-----------------------------------------------------------------------------</b> ";
var row_5:String = "<FONT FACE ='Verdana' SIZE ='12'><b>CC/MOI</b> MVA, decreased LOC</FONT>";
var row_6:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Respirations</b> 20</FONT>";
var row_7:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Pulse</b> Radial at 110, strong</FONT>";
var row_8:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Mental Status</b> Awake, but has difficulty with attention</FONT>";
var row_9:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Skin Signs</b> Cool, moist, pale</FONT>";
var row_10:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Obvious Trauma</b> None</FONT>";
var row_11:String = "<FONT FACE ='Verdana' SIZE ='12'><b>Blood Pressure</b> 112/palp (later 120/74)</FONT>";
// Sets two tabstops, at 25 and 100 points.
table_txt.htmlText = "<textformat tabstops='[25,120]'>";
table_txt.htmlText += rowHeaders;
table_txt.htmlText += row_1;
table_txt.htmlText += row_2 ;
table_txt.htmlText += row_3 ;
table_txt.htmlText += row_4 ;
table_txt.htmlText += row_5 ;
table_txt.htmlText += row_6 ;
table_txt.htmlText += row_7 ;
table_txt.htmlText += row_8 ;
table_txt.htmlText += row_9 ;
table_txt.htmlText += row_10 ;
table_txt.htmlText += row_11 ;
table_txt.htmlText += "</textformat>";
This works great with the text populating two columns. But the 2nd column in row_3 and row_8 drops down to the next line, but does so in column 1.
Is there a way to have it drop a line but align with the 2nd column tabstop?
Thanks for any help
Greg
<--- Multiline Textfields --->
This i wat i do:
I have a multiline text field - I record the contents using asp. I pass the contents of the field thru the Query String to the page.
This is the problem
When the contents get copied thru the query string it loses all return carriages. This is a big problem as it is an address i am recording
What i need?
Is the replace the return cariages with <br>'s and then pass it thru the query string?
What is the character code for return cariages?
Thanks in advance.
Returns In Multiline Being Sent To XML
ok....dumb question here.
i have a multiline text box for users to enter a short message into.
when they hit <enter> as they are typing what character are they creating? would this be a "/n" or a "/r" ?
its my xml file ends up looking like this:
Code:
<message> blah blah bla
blalbhal
blah
</message>
....i would ideally like these invisible returns to be replaced....any ideas?
robocop
Multiline Graph
anyone knows how to create a multiline graph with the 12 months on the x axis nd value from$20,00 to $40,000 on the y axis?? ?
HTML Multiline?
Hello, I have a question..... again.. jaj. Its just that Iam frustrated with this work I am doing..
Ok, the question is if its possible for a textField to be multiline when it works as html, because I have the property for multiline enabled, but with no results.
This was added: I forgot to mention something important. The text in the textField is being loaded from an external file, all the html code is there. There are parts in the code that use bullets, and if I use a <br>, a new bullet is created, and the message will not make sense separated by unecessary bullets.
CreateTextField And Multiline
I'm trying to make a dynamic text field multiline, and for some reason, it won't work. I can see the text, but it doesn't multiline.
I'm creating a text box inside an empty movie clip. TextClip1 is the empty movie clip.
ActionScript Code:
with(TextClip1)
{
createTextField("TitleBox", 1, 0, 0, 300, 100);
with(TitleBox)
{
text = recArray[0].Title;
selectable = true;
multiline = true;
setTextFormat(TitleFormat);
}
}
When I review my variables, nothing appears to be wrong. the multiline is set to true... so I have no idea what is going wrong.
Multiline Problem?
I have a dynamic text box and have set the following so the text written to it will break to a second line if need be.:
textBox_txt.multiline = true;
textBox_txt.wordWrap = true;
On the Mac it's fine however it doesn't break on a PC.
Any suggestions?
Detect Multiline
Hi, I've created a search device and some of the results shown have more than one line (or more than one result). From the following function, how can I tell if more than one item has been added to the results field?
Attach Code
function fChkInput():Void {
if (_root.searchPanel_mc.result_txt.text == "") {
for (i=0; i<aAllNames.length; i++) {
if (aAllNames[i] == sSearch || aAllNames[i].toLowerCase() == sSearch) {
searchPanel_mc.result_txt.htmlText += aAllListings[i].attributes.extension+" "+aAllListings[i].attributes.cell+" "+aAllListings[i].attributes.email;
} else {
//searchPanel_mc.result_txt.text = "Not found";
}
}
}
}
Damned Multiline
Code:
this.bg.attachMovie("vidbg_mc", "vidbg_mc", this.getNextHighestDepth());
this.createEmptyMovieClip("holder", this.getNextHighestDepth());
// text field
var whichfile:String = vidfileArr[i];
var whichlabel:String = vidlabelArr[i];
var whichthumb:String = vidthumbArr[i];
var whichdesc:String = viddescArr[i];
this.holder.createTextField("label_txt", this.holder.getNextHighestDepth(), 68, 5, 160, 60);
this.holder.label_txt.multiline = true;
this.holder.label_txt.text = whichlabel+"
"+whichdesc;
var myTextFormat:TextFormat = new TextFormat();
myTextFormat.font = "Arial";
myTextFormat.size = 11;
myTextFormat.bold = false;
myTextFormat.color = 0xFFFFFF;
this.holder.label_txt.selectable = false;
this.holder.label_txt.setTextFormat(myTextFormat);
//*/
// Preload thumbnail
this.holder.createEmptyMovieClip("vidthumb_mc", this.holder.getNextHighestDepth());
mcloader.loadClip("newsite/kaleo/video/thumbs/"+whichthumb, this.holder.vidthumb_mc);
// button functions
this.holder.onRelease = function(){
// load video
//_root.vids_mc.vidnav_mc.header_txt.text = whichlabel;
trace(this);
ns.play("newsite/kaleo/video/flv/"+whichfile);
}
for some messed up reason I can't get the text boxes to display multiline... this bit of code is from a movie clip prototype function. syntax seems to be alright, anybody know what would cause this not to work?
Multiline Alert
Hi, i was wondering how you display multilines in the alert component.
e.g.
The following errors occurred:
- You didnt fill in a username
- You didnt fill in a password
- etc
- etc
Any ideas??
Regards,
Martin
Computing Help And Info:
http://www.webrevolt.biz
Multiline Textbox
I am trying to create a multiline text box but am only getting the first line of text
textStr = str1 + "
" + str2;
txt.setNewTextFormat(nameTextFormat);
txt.selectable = false;
txt.embedFonts = true; //necessary for next line
txt.multiline = true;
txt.wordWrap = true;
txt.text = textStr;
RadioButton Multiline
Can a radioButton have a multiline setting for the label. I'm using Flash Pro MX 2004. I can't find a way to do it, so i was just wondering if that is possible. Thanks.
MultiLine TextField
Hello!
i have a small but very strange problem .
i would like to create an autosize textField..
ActionScript Code:
var my_txt:TextField=path.createTextField("my_txt", depth, __x, __y, __width, __height);
my_txt.autoSize = "justify";
my_txt.selectable=isSelectable;
my_txt.wordWrap = true;
my_txt.multiline = true;
my_txt.text = textToDisplay;
wich is still impossible is that my text field could be multiline without giving it the max height for the estimated number of linees.
else flash shows a single line !!
Multiline Textfield With Newlines
Hi all,
I am currently working on some little things in Flash in connection with PHP like sending e-mail etc.
My problem is the multiline textfield. When I have carriage/returns in my text and send this text to the PHP file I get the text without the carriage/returns... I tried nl2br($text) in PHP but it stays the same.
Does anybody know how to solve this?
Thanks,
Stefan
NO Scrolling On Multiline Textfield...
HELP!!! (please)
I need help. I need to make a multiline text field that does not scroll, it just stops letting you type when you have filled the text field up!
I could set the text field to limit chars, but that doesn't solve my problem, because the users will be using the return carage, and that would still allow them to type past the bottom of the text field. I just need to limit them to 20 rows, and 40 coloms of text. is there an actionscript way?
I am using flash 4, but would be willing to use 5, or MX if I need to to make this work.
Any one have any idea? Thanks!
End Of The Line In The Multiline Text
Hi!
how can I find the end of the line in the multiline dynamic text field??
I need the index of the first character at the last line..
thanx in advance
Multiline Input Text
I want to create an input box with multiline property and when I press "Enter" key in the input box, the cursor will go to next line even though the cursor has not reached the end of the box width. Therefore the user can input any text and wrap at any point.
CreateTextField, Multiline Problem
Hi,
I tried createTextField and then I set the textfield to multiline true. Although the text showed up, it was only in one line. Does anybody have experience with that or if not can anybody try it out?
Thanks for any help
Multiline Text For Checkbox
Is there a way to create multiline text labels for the Checkbox Component.
I am creating a multi choice quiz using the MM multi choice components but have a number of questions which are rather verbose and will not fit on one line. How do I extend the text label to multiline?
Regards,
Matt
Multiline Dynamic Text?
ok lets say i have a movie that is ONLY a multiline dynamic text field, but i want the field to have as small of a height as possible while still fitting all the text that is sent to it. so basically, if it is sent enough characters to have 9 lines of text, i want the field and the movie to adjust to that height. is this possible?
TextField, No WordWrap, No Multiline
Hey Gang,
My text field does not seem willing to wordWrap or multiline. Can someone tell me what is wrong with this?
this.createTextField("question_txt", 1, -240, -53, 445, 0);
question_txt.text= _root["question_" +_root.randNum][0];
question_txt.setTextFormat(_root.formatColor);
question_txt.setTextFormat(_root.formatSize);
question_txt.setTextFormat(_root.formatFont);
question_txt.multiline= true;
question_txt.wordWrap= true;
question_txt.autoSize= "left";
Multiline Input Text
Hello everyone,
just curious if there is a way to "reset" a multiline input text field.
I know how to clear it after submit, but how do I make the default position at the top after submission?
Thanks in advance
-Adam
Multiline Form Question
I have an email form set up to be processed by an ASP page. There are 3 fields, 2 single line, one multiline, all works great except if you do a carriage return in the multiline field. All text below the return does not get included in the email form (the recipient sees no text below the return in their email).
Is this a flash or ASP handling problem. Anyone come accross the same problem.
Thank you!
Multiline Parameter (component) ?
Does anybody know how to give a component parameter a value of a multiline text, directly in the component panel (not using/referring/'eval'-ing extra actions or textfield!)?
t.i.a
P.
Multiline Parameter (component) ?
Does anybody know how to give a component parameter a value of a multiline text, directly in the component panel (not using/referring/'eval'-ing extra actions or textfield!)?
t.i.a
P.
Dynamic Text W/ Multiline?
I'm having a dynamic text variable, named "text", but i couldn't make it to printed some text in multilines.
E.g: text=string("I haven't seen any one..
..in many years. ");
--> It didnt work.
> At "
" (I mean without quotes ^^) I wanted to break that line to 2 lines. How can I do?
Thanks
Listbox Multiline Selected
Hi all,
I'm using Flash MX.
I'm trying to create a scrollable navigation menu using a listbox component, populated by an XML file. I'm using a listbox instead of a textbox because I need to handle onclick events.
Occationally, a menu item will be longer than one line. By default, the listbox will not wrap the text. Obviously I would like the text to wrap.
I was able to add the following lines of code to the FLabel symbol in the component library...
this.labelField.wordWrap = true;
this.labelField.multiline = true;
this.labelField.autoSize = true;
This works until the menu item is selected. Once selected, the item appears to return back to a single line.
Is it possible to make a listbox more multiline friendly?
Thanks in advance.
Joe
How To Select Multiline In Listbox
I want to connect Flash and MySQL.
Flash will display a table of MySQL in a listbox(or something like that). When I select lines and then press a button, values of all nummered selected lines will be saved back into MySQL.
My problem is I don't know how to select multiline at once (not all, because there is a button perform function SELECT/DESELECT ALL).
Any idea??
Multiline Listbox Component
Hi,
I was wondering if anyone has come across any tutorials or sites that talk about customizing the UI component: Listbox? I have searched and have had no luck with finding anything. Or perhaps someone has had to do it themselves even?
I basically need my labels in the listbox to be able to wrap if the text is longer than the width of the listbox.
I am in a real pinch and hope that you can get back to me soon on this matter.
Thanks in advance for your help.
-- Nik
Multiline Text - Where's Last Line?
I have a dynamic multiline text box, that I'm applying an autoSize = "center" on. Tracing the height of the box, I see that the autosize is working, although it's not showing the last line of text for some reason.
http://www.tetdesign.com/misc/multiline/
Here's the script, and you can download the .fla here to dig in if you'd like :
this.playTitle1 = "Josh Childress Flys High";
this.playTitle2 = "Lebron James Jams Over the Lakers";
this.playTitle3 = "Kyle Korver Hits From the Outside";
//place copy for plays
function placeCopy():Void {
for (var i = 1; i<4; i++) {
//drop title
this["videoGrab"+i].playTitle.text = this["playTitle"+i];
this["videoGrab"+i].playTitle.multiline = true;
this["videoGrab"+i].playTitle.wordWrap = true;
this["videoGrab"+i].playTitle.autoSize = "center";
trace(this["videoGrab"+i].playTitle._height);
}
}
Is It Possible To Have Multiline Cell In DataGrid?
I am trying to get my datagrid to display multiline text but am having no joy
This is what I have tried but it gives me this error
Code:
TypeError: Error #2007: Parameter child must be non-null.
Here is my code:
Code:
function bldRosterGrid(dg:DataGrid){
dg.setSize(340, 300);
dg.columns = ["No", "AssessmentCriteria", "MarkRange", "Mark"];
dg.columns[0].width = 40;
dg.columns[1].width = 120;
dg.columns[2].width = 80;
dg.columns[3].width = 40;
dg.move(20,150);
dg.rowHeight = 40; // Allows for 2 lines of text at default text size.
// ------------------------------------------
// Rename column headings with readable names
// ------------------------------------------
dg.getColumnAt(0).headerText = "No.";
dg.getColumnAt(1).headerText = "Assessment Criteria";
dg.getColumnAt(2).headerText = "Mark Range";
dg.resizableColumns = true;
dg.verticalScrollPolicy = ScrollPolicy.AUTO;
var col1:DataGridColumn = new DataGridColumn();
col1 = dg.getColumnAt(1);
col1.cellRenderer = "MultiLineCell";
};
Any ideas?
ComboBox And Multiline Items
hi,
how can I set the textfoeld items in the comboBox to multline and wordWrap?
I've tried something like:
Code:
cb.getChildAt(1).getChildAt(0).multiline =true;
cb.getChildAt(1).getChildAt(0).wordWrap =true;
or:
Code:
cb.setStyle("wordWrap",true);
cb.setStyle("multiline",true);
or:
Code:
cb.dropdown.setStyle("wordWrap",true);
cb.dropdown.setStyle("multiline",true);
but none of thos simple ways brought me luck. Should i work with the CellRendere class to do this?
thanks,
Jerryj.
TextField.multiline Properties.
Here is a weird one....
I created a TextField dynamically set the .multiline = true; (it only takes Boolean values). Now I tried to TextField.autoSize = "left"; and it doesn't really work because multiline, when set dynamically, is set to multiline no wrap.
Well that sucks, because the TextField won't expand vertically.
Oh well, I guess just make a dummy clip on the Stage and adjust that.
Quote:
If the value of autosize is "left" and the text field line type is set to Multiline in the text Property inspector, then the text field expands or contracts its right and bottom sides to fit all contained text.
If the value of autosize is "left" and the text field line type is set to Multiline No Wrap in the text Property inspector, then the text field expands or contracts only its right side to fit all contained text.
Multiline String Vars
Does anyone know if it is possible to have multiple lines of text assigned to a string variable in actionscript 2.0. Basically I have a class that parses XML data passed as a string. Originally erasing the line breaks and putting the XML data onto one line was not a big deal but now I am working with XML files that are 5k+ in length. Any help would be greatly appreciated.
Thanks in advance,
-Derek
Rendering Multiline UITextField
First, let me say that I am an AS 3 newb. I've been racking my brain with this an haven't been able to figure it out. This class is used in the FishEye component. From what I gather, its the class that determines whether a text label will be bitmapped or rendered as text. My issue is that I need to make the fields multiline, and force a maximum width of say, 105 px for each text field.
Even if I force a new line of text by adding
in the middle of the string, the labels are positioned with width/height values as if the first line is all that exists. How can I change this code to force it to re-evaluate the text width & height values of a multiline?
Code:
package qs.controls
{
import mx.core.UIComponent;
import mx.core.UITextField;
import mx.core.IDataRenderer;
import flash.geom.*;
import flash.display.*
import flash.text.TextLineMetrics;;
/**
* Color of text in the component, including the component label.
* The default value is <code>0x0B333C</code>.
*/
[Style(name="color", type="uint", format="Color", inherit="yes")]
/**
* Color of the component if it is disabled.
* The default value is <code>0xAAB3B3</code>.
*/
[Style(name="disabledColor", type="uint", format="Color", inherit="yes")]
/**
* Name of the font to use.
* Unlike in a full CSS implementation,
* comma-separated lists are not supported.
* You can use any font family name.
* If you specify a generic font name,
* it is converted to an appropriate device font.
* The default value is <code>"Verdana"</code>.
*/
[Style(name="fontFamily", type="String", inherit="yes")]
/**
* Height of the text in pixels.
* The default value is 10.
*/
[Style(name="fontSize", type="Number", format="Length", inherit="yes")]
/**
* Determines whether the text is italic font.
* Recognized values are <code>"normal"</code> and <code>"italic"</code>.
* The default value is <code>normal</code>.
*/
[Style(name="fontStyle", type="String", enumeration="normal,italic", inherit="yes")]
/**
* Determines whether the text is boldface.
* Recognized values are <code>"normal"</code> and <code>"bold"</code>.
* The default value is <code>normal</code>.
*/
[Style(name="fontWeight", type="String", enumeration="normal,bold", inherit="yes")]
/**
* Alignment of text within a container.
* Possible values are <code>"left"</code>, <code>"right"</code>,
* or <code>"center"</code>.
* The default value is <code>"left"</code>.<br>
* For the Button, LinkButton, and AccordionHeader components,
* the default value is <code>"center"</code>.
* For these components, this property is only recognized when the
* <code>labelPlacement</code> property is set to <code>"left"</code> or
* <code>"right"</code>.
* If <code>labelPlacement</code> is set to <code>"top"</code> or
* <code>"bottom"</code>, the text and any icon are centered.
*/
[Style(name="textAlign", type="String", enumeration="left,center,right", inherit="yes")]
/**
* Determines whether the text is underlined.
* Possible values are <code>"none"</code> and <code>"underline"</code>.
* The default value is <code>none</code>.
*/
[Style(name="textDecoration", type="String", enumeration="none,underline", inherit="no")]
/**
* Offset of first line of text from the left side of the container.
* The default value is 0.
*/
[Style(name="textIndent", type="Number", format="Length", inherit="yes")]
public class CachedLabel extends UIComponent implements IDataRenderer
{
private var _label:UITextField;
private var _bitmap:Bitmap;
private var _capturedText:BitmapData;
private static var xUnit:Point = new Point(1,0);
private static var origin:Point = new Point(0,0);
private var _data:Object;
private var _text:String = "";
private var _cachePolicy:String = "auto";
public function CachedLabel()
{
super();
}
public function set useCache(value:String):void
{
_cachePolicy = value;
invalidateDisplayList();
}
public function get useCache():String
{
return _cachePolicy;
}
override protected function createChildren():void
{
super.createChildren();
_label = new UITextField();
_label.multiline = true;
_label.selectable = false;
_label.autoSize = "left";
_label.text = _text;
addChild(_label);
}
override protected function measure():void
{
_label.validateNow();
if(_label.embedFonts)
{
measuredWidth = _label.measuredWidth + 6;
measuredHeight = _label.measuredHeight + 4;
}
else
{
var metrics:TextLineMetrics = measureText(_text);
measuredWidth = metrics.width + 6;
measuredHeight = metrics.height + 4;
}
}
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void
{
_label.validateNow();
_label.setActualSize(unscaledWidth, unscaledHeight );
var localX:Point;
var localO:Point;
var useLabel:Boolean = true;
switch(_cachePolicy)
{
case "off":
useLabel = true;
break;
case "on":
useLabel = false;
break;
case "auto":
if(_label.embedFonts == false && unscaledWidth > 0 && unscaledHeight > 0)
{
localX = globalToLocal(xUnit);
localO = globalToLocal(origin);
useLabel = (localX.x - localO.x) == 1 && (localX.y - localO.y) == 0;
}
}
if(unscaledHeight <= 1 || unscaledWidth <= 1)
useLabel = true;
if(useLabel)
{
if(_bitmap != null)
{
removeChild(_bitmap);
_bitmap = null;
}
_label.visible = true;
}
else
{
_label.visible = false;
if(_capturedText == null || _capturedText.width != unscaledWidth || _capturedText.height != unscaledHeight )
{
_capturedText = new BitmapData(unscaledWidth,unscaledHeight);
if(_bitmap != null)
{
removeChild(_bitmap);
_bitmap = null;
}
}
if(_bitmap == null)
{
_bitmap = new Bitmap(_capturedText);
_bitmap.smoothing = true;
addChild(_bitmap);
}
_capturedText.fillRect(new Rectangle(0,0,unscaledWidth,unscaledHeight),0);
_capturedText.draw(_label);
}
}
[Inspectable(environment="none")]
public function get data():Object
{
return _data;
}
/**
* @private
*/
public function set data(value:Object):void
{
if( value == _data)
return;
_data = value;
_text = String(value);
if(_label != null)
_label.text = (_text == null)? "":_text;
invalidateSize();
invalidateDisplayList();
}
override public function invalidateSize():void
{
super.invalidateSize();
}
}
}
|