# Simple text editor

**URL:** <https://forum.kirupa.com/t/simple-text-editor/264472>\
**Category:** flash\
**Created:** [June 26, 2008, 1:05pm UTC](https://forum.kirupa.com/t/simple-text-editor/264472 "2008-06-26T13:05:16Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gag4n](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@gag4n](https://forum.kirupa.com/u/gag4n)\
**Post date:** [June 26, 2008, 1:05pm UTC](https://forum.kirupa.com/t/simple-text-editor/264472/1 "2008-06-26T13:05:16Z")

</div>

Can someone advise me on how I can click anywhere on the canvas/stage to create a text field where you can input text.

I have seen similar functionality at [www.imagination3.com](http://www.imagination3.com/) where you can see the function if you go to TOOLS \> TYPE.

Any assistance will be appreciated.

---

<div class="post-metadata">

**Author:** ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)\
**Post date:** [June 27, 2008, 8:29pm UTC](https://forum.kirupa.com/t/simple-text-editor/264472/2 "2008-06-27T20:29:55Z")

</div>

Create a MOUSE\_CLICK listener and in callback put this in general

```auto
function click(event:MouseEvent):void {
var tf:TextField=new TextField();
tf.defaultTextFormat=someTF;
tf.x=event.mouseX;
tf.y=event.mouseY - tf.height / 2;
addChild(tf);
//here should be some focus handling code
}

```

---

<div class="post-metadata">

**Author:** ![gag4n](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@gag4n](https://forum.kirupa.com/u/gag4n)\
**Post date:** [June 30, 2008, 2:54pm UTC](https://forum.kirupa.com/t/simple-text-editor/264472/3 "2008-06-30T14:54:49Z")

</div>

I’ve got this working using the following code

```auto
function goTXT(e:MouseEvent) {
                var txt:TextField = new TextField();
                
                txt.type = TextFieldType.INPUT;
                txt.x = e.localX+25;
                txt.y = e.localY+50;
                stage.focus = txt;
                txt.autoSize = TextFieldAutoSize.LEFT;
                mcCanvas.addChild(txt);

            }

```

Does anyone know how/if I can apply text formating? Would I use setTextFormat/TextFormat?

---

<div class="post-metadata">

**Author:** ![Templarian](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/templarian/32/7152_2.png) [@Templarian](https://forum.kirupa.com/u/Templarian)\
**Post date:** [June 30, 2008, 3:01pm UTC](https://forum.kirupa.com/t/simple-text-editor/264472/4 "2008-06-30T15:01:27Z")

</div>

Place this under your var txt:TextField = ect…

```auto
var defaultFormat:TextFormat = new TextFormat();
defaultFormat.font = "Courier New";
defaultFormat.color = 0xFF00FF;
defaultFormat.size = 11;

txt.defaultTextFormat = defaultFormat;

```

---

<div class="post-metadata">

**Author:** ![gag4n](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@gag4n](https://forum.kirupa.com/u/gag4n)\
**Post date:** [June 30, 2008, 3:03pm UTC](https://forum.kirupa.com/t/simple-text-editor/264472/5 "2008-06-30T15:03:25Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![gag4n](https://avatars.discourse-cdn.com/v4/letter/g/df788c/32.png) [@gag4n](https://forum.kirupa.com/u/gag4n)\
**Post date:** [July 2, 2008, 8:40am UTC](https://forum.kirupa.com/t/simple-text-editor/264472/6 "2008-07-02T08:40:01Z")

</div>

I wanted to know if it is possible to save the data (text field x y coordinates, text data, formatting…) externally and then reload at a later date? If it is possible to save the information/data can it be loaded via XML?

Thanks
