Simple text editor

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 where you can see the function if you go to TOOLS > TYPE.

Any assistance will be appreciated.

Create a MOUSE_CLICK listener and in callback put this in general

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
}

I’ve got this working using the following code

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?

Place this under your var txt:TextField = ect…

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

txt.defaultTextFormat = defaultFormat;

Thanks

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