• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 227
  • Last Modified:

i like to append a text into a text area where the mouse caret is...

Hi,
i like to append a text into a text area where the mouse caret is,
and then set the mouse caret at the end of the text area.
can this be done in flash 7??

thanks
0
mte01
Asked:
mte01
  • 3
  • 3
  • 2
  • +1
2 Solutions
 
MontoyaProcess Improvement MgrCommented:
a texbox component allows that, but Im not sure if that is what you mean. Just make sure the "editable" parameter is set to true.
0
 
blue-genieCommented:
Hi, also not sure what you mean.
Do you want the user to simply insert the cursor into the text field and type.
Or are you thinking along other lines?
0
 
mte01Author Commented:
Hi guys,
i have this button, that the user can click
if the original text was: 1234
and the mouse caret was after the 2,
and if the user clicked on this button: the text will become 12~34
it's like inserting text at a specific position, not at the end, i was looking now at the function Selection.getCaretIndex()
this will return the caret index. but i cant set the caret index of the text area, like after adding the character "~"  i want the mouse caret to be at the end of the text so that when the user start typing the text will be appended at the end.. dont know if this is clear, plz tell me if it's not and ill try to make it clearer...
Kind regards
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
blue-genieCommented:
i've just tried fiddling with the getCaretIndex() and it keeps returning to me the number of characters in the textfield rather than the caret index - i'm thinking it might have something to do with the loss of focus upon clicking the button, but I can't be sure, i've tried setting the focus back to the text area upon clicking but no luck there either.
Thing is, if you're losing focus,  by clicking a button, you're gonna have problems. Unless you incorporate listeners maybe and store that value in a variable ... i'm just thinking out loud there.

i have a sneaky suspicion this can't be done. I stand to be corrected.
If you can get the getCaretIndex() to work, you should be able then to use the setSelection() to the getEndIndex() - in theory at least.

sorry can't be any more help.
blu.
0
 
Aneesh ChopraCommented:
past the following code in a new FLA's first frame and compile the swf
----------
this.createTextField("pos_txt", this.getNextHighestDepth(), 50, 20, 100, 22);
this.createTextField("content_txt", this.getNextHighestDepth(), 50, 50, 400, 300);
content_txt.border = true;
content_txt.type = "input";
content_txt.wordWrap = true;
content_txt.multiline = true;
content_txt.onChanged = getCaretPos;

var keyListener:Object = new Object();
keyListener.onKeyUp = getCaretPos;
Key.addListener(keyListener);

var mouseListener:Object = new Object();
mouseListener.onMouseUp = getCaretPos;
Mouse.addListener(mouseListener);

function getCaretPos() {
    pos_txt.text = Selection.getCaretIndex();
}
--------------

Rgds
Aneesh
0
 
mte01Author Commented:
thanks aneeshchopra
i can see the caret pos, the problem is that i need to set the caret pos, like i want when i click on a button to set the caret to the position 0 (or any number).
one more time thanks guys for the help for a big part of the problem is fixed.
Best regards,
0
 
Aneesh ChopraCommented:
Ok, here is the updated code

1.
copy the following code in a new FLA's first frame
----------
this.createTextField("pos_txt", this.getNextHighestDepth(), 50, 20, 100, 22);
this.createTextField("content_txt", this.getNextHighestDepth(), 50, 50, 400, 300);
content_txt.border = true;
content_txt.type = "input";
content_txt.wordWrap = true;
content_txt.multiline = true;
content_txt.onChanged = getCaretPos;
var keyListener:Object = new Object();
keyListener.onKeyUp = getCaretPos;
Key.addListener(keyListener);
var mouseListener:Object = new Object();
mouseListener.onMouseUp = getCaretPos;
Mouse.addListener(mouseListener);
function getCaretPos()
{
      pos_txt.text = Selection.getCaretIndex();
}

btn.onPress = function()
{
      this._parent.appendText("abc");
};
appendText = function (txt)
{
      tmp = content_txt.text;
      tmp = tmp.substring(0, pos_txt.text)+txt+tmp.substring(pos_txt.text);
      content_txt.text = tmp;
};
-----------

2.
create a button with instance name "btn"

3.
compile the swf, now put the caret anywhere in the textfield and press button..


Rgds
Aneesh
0
 
MontoyaProcess Improvement MgrCommented:
***bowing to Aneesh***** thanks for saving me some time. I was about to try this. :)

0
 
mte01Author Commented:
:) thanks Aneesh it's perfect.
0
 
Aneesh ChopraCommented:
Welcome,
but you still haven't accepted the comments...
0

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now