AS3 - Turn classic textfield into TLF textfield - actionscript-3

I have a classic textfield on stage that I would like to turn into a TLF textfield. How can this be done?
Thank you. Uli

If on the stage in Flash Pro, you could simply change the control.
From classic text:
To TLF text:
Programmatically I don't believe there's typecasting between flash.text.TextField and fl.text.TLFTextField.
Both share a .text property; however, are different in terms of capability such as html and text flow.

Related

Form elements do not appear in output

I have created a Flex project in Flash Builder 4.5.
Next I added fl.controls libraries (and then mx.controls libraries) in the project.
I am adding a screenshot so you can see the setup and the code.
However when I run/debug it, nothing appears in there. Totally white.
I've worked with fl.controls before, I used Flash CS5 to compile the ActionScript project and they worked correctly.
Is there any particular reason why it does not work in Flash Builder?
UPDATE: When I add graphics to the text input, i.e.
ti.graphics.beginFill(0xFF0000);
ti.graphics.drawRect(0, 0, 100, 30);
ti.graphics.endFill();
I do see a red rectangle shape. But still no editable text input box. I tried setting ti.editable = true but no use.
Try this:
Create a new FLA in Flash Professional. Add the TextInput component to your library. Notice that not only does the TextInput class get added to the library, but also a folder of "Component Assets" - skins and such. Flash Professional components are not just code - they are code and graphics.
If you want to use fl.controls.TextInput in Flash Builder, you can publish that FLA you just created with the "export swc" option checked. Include that swc in your Flash Builder project, and you'll be able to instantiate the TextInput in your code. If you want to add other Flash components, add them to the library in the FLA and republish the swc.
I would prefer using Flex itself, it will speed up your development. It's simple and does a lot of work for you.
If you do not want to do this you should give your text some properties like width, height, textFormat or use a css document for the text format. You could also give your text a border ( it should be a property of the TextInput ).
Do not forget to set the text format, otherwise the TextField doesn't know which font to use.
Sample for TextInput ( Bottom of Page )
http://help.adobe.com/de_DE/FlashPlatform/reference/actionscript/3/fl/controls/TextInput.html
Sample for Flex
http://help.adobe.com/de_DE/FlashPlatform/reference/actionscript/3/spark/components/RichEditableText.html
You can try this code:
private var ti:TextField = new TextField();
public function FormText(){
//adds ti possibly underneath 'this': stage.addChild(ti);
//adds ti on top of 'this':
stage.addChildAt(ti,getChildIndex(this));
// makes the TextField editable:
ti.type = TextFieldType.INPUT;
}
This should not only make sure that the TextField exists when the class is instantiated, but also puts the form in front of the class.
But this also assumes that the class has been added to the stage; so it may be better to add it like this:
private var ti:TextField = new TextField();
public function FormText(){
addEventListener(Event.ADDED_TO_STAGE, addedHnd);
}
private function addedHnd(e:Event)
{
removeEventListener(Event.ADDED_TO_STAGE, addedHnd);
//adds ti possibly underneath 'this': stage.addChild(ti);
//adds ti on top of 'this':
stage.addChildAt(ti,getChildIndex(this));
// makes the TextField editable:
ti.type = TextFieldType.INPUT;
}
Please review the TextField docs, too.
Why do you add your control to the stage? You should just add it to your form. i.e. this.addChild(ti)

How to stop/convert TLF textfield used in flash files when you have list to search?

My designer provides me lots of MovieClips containing buttons and its states and most of them contain a TLF TextField.
Now I do not want to check each MovieClip where a TLF TextField is used.
Can I know exactly in which MovieClips and buttons a TLF TextFields has been used so that I can convert them to a classic TextField, or any method to convert all TLF TextFields to classic automatically by the compiler itself?
I tried deleting the TLF library from publish settings: it starts giving me an error, but still not pointing me to where TLF TextFields are being used.
You can change publishing settings to Flash Player 9. TLF wasn't around then, so the IDE will automatically convert them to classic text. Note, this DOES change the visual appearance of the text, AND it may have other effects on your FLA.

Is there a way to add text to sprite or movieclip not using TextField class?

Is there a way to add text programmatically in as3 to a Sprite or a MovieClip without using the class TextField
TextField inherits from InteractiveObject which is kind of heavy for what I want to do: just display text (i.e. I don't want to interact with the text).
Note: I'm aware that there is a property selectable to make the textfield not selectable. This is not the point.
Thank you
There are two ways that come to mind. The first being this whereby a string is written to bitmap data: How to draw a string on BitmapData
Second, you could try this fast font rendering library (although I have not tried it myself) lab.polygonal.de/2009/12/15/font-rendering-with-the-fp10-drawing-api/
Both these solutions seem to bypass the need for creating a textfield (except the first where it gets used to create but then is discarded).

Bold and regular font in dynamic text under a mask In Flash with AS3

I have this text "my text is <b>bold</b> and regular".
I want "<b>bold</b>" to be... well, let's say... bold !
I have a mask layer under which there is a text field.
The text field shows htmlText, and i must embed chars. If not embedded, it doesn't display because of the mask. So the solution of importing 2 user fonts ( one bold and one regular) does not work.
I'm thinking this is impossible to do with Flash... Maybe I wrong, am I ?
Thank you !
The problem is that when you embed the characters, it only embeds normal-weight font characters. The Mask is a red-herring; this will happen whether you mask the TextField or not.
You can solve the problem however! Create another TextField in your FLA (off-stage, I imagine) with the same font at the same size, but set the font to bold. Embed characters in that TextField too.
Then, the bold characters in your first TextField will display as bold.
There are other ways to achieve this, especially if you don't use the Flash IDE to compile your swfs (if you use MXML through FDT, FlexBuilder, FlashBuilder or FlashDevelop for example). If you do, then you should lookup how to embed fonts using [Embed] metadata.

AS3 access dynamic textfield on stage from a class

I have this dynamic textfield on stage, and I want to access it from my xmlloader class, so it can display text from my xml file. I just can't figure out a way to do it.
I found the answer:
MovieClip(root).thetextfieldonstage.text = "yep";
can call the textfield from class.