A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: simple text editor

  1. #1
    Junior Member
    Join Date
    May 2008
    Posts
    19

    Question 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.

  2. #2
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    try this:
    PHP Code:
    import fl.controls.TextInput;

    stage.addEventListener(MouseEvent.CLICKgoTXT);

    function 
    goTXT(e:MouseEvent):void{
        if(
    e.target is TextField){
            return;
        } else {
            var 
    t:TextInput = new TextInput();
            
    addChild(t);
            
    t.e.stageX;
            
    t.e.stageY;
        }

    And note that you'll need to pull the textInput component into the library to work.

  3. #3
    Junior Member
    Join Date
    May 2008
    Posts
    19

    Thumbs up

    Hey thanks.

  4. #4
    Junior Member
    Join Date
    May 2008
    Posts
    19
    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

  5. #5
    Junior Member
    Join Date
    May 2008
    Posts
    19

    Question

    How would you get a 'COPY' 'CUT' 'PASTE" function to work with the text editor? The same as CONTROL + C, CONTROL + X, CONTROL + V... but using buttons instead of keys.

    Thanks

  6. #6
    Ө_ө sleepy mod
    Join Date
    Mar 2003
    Location
    Oregon, USA
    Posts
    2,441
    Saving the textfields wouldnt be too hard...just a matter of recording all the variables about each field and serializing it...just make sure you record everything you'd want to get back later. You could use xml like this:

    PHP Code:
    <textfield x=30 y=200 width=150 multiline=true autosize=left>
        
    text text text.
    </
    textfield
    note: If this is for the public, make sure you scrub the text values before you save them - you don't want people injecting code or breaking your xml!

    To create copy functionality, you would take the value of the textfield (eg. the string inside it), and substring that to the selectionBeginIndex and selectionEndIndex, that would give you a string with just the 'copied' text. Then you can either save that to a variable or use System.setClipboard() to force the text into the OS clipboard.

    For cut you would do the same thing except you'd also substring the text before and after the selection points and concatenate that to give you the remaining text (ie. splice the selected text out).

    Pasting is a little trickier since you can't access the same System.clipboard so if you go that route you'd need to use the system's ctrl+v command. If you saved the text to a variable, you can split the textfield into two strings using the caretIndex, and recombine with your copied string in the middle.

    Hope that helps - and if you can, post the working version, it sounds like a cool project!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center