PDA

View Full Version : Selecting text from one and transferring to another



vshankar
October 10th, 2001, 05:26 AM
I have one input text box one dynamic textbox and two button in my flash movie. What I want is Is there any way any code such that I enter text in my input box and i select a part of it I click the transfer button and the selected should be copied to the dynamic text box that is whatever i have selected in the text box should be copied to the dynamic text box using the button.

Second thing in the Input box i enter text and I select some text and on clicking the second button the selected should be bolded/underlined as it happens in word or any text editing tool. Is there any way around to do these.

Please help solve this issue. I am getting mad working around this.

regards
shankar

thoriphes
October 10th, 2001, 11:35 AM
yes.

eyezberg
October 10th, 2001, 12:05 PM
huh? thoriphes, now that must've been helpfull, lol!

suprabeener
October 10th, 2001, 03:32 PM
vshankar,

this gave me more trouble than i anticipated. make a movie somewhere and put this in it:

onClipEvent(keyDown){
&nbsp &nbsp &nbsp &nbsp if (Key.getCode() == Key.ENTER) {
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp _root.outputtext = _root.inputtext.slice(Selection.getBeginIndex(),Se lection.getEndIndex());
&nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp &nbsp trace(_root.inputtext);
&nbsp &nbsp &nbsp &nbsp }
}


now it will work when you press enter.

the problem i was having with the button is that when i clicked the button it defocused and deselected the text, so all of the Selection references were useless.

let me know if you find a way around it.

re: the second thing. i don't see an easy way to do this.
you might split it into an array based on the selection points.
so you have:

array[0]=before selected text
array[1]=selected text
array[2]=after selected text

and then put them together like this:

newText=array[0]+""+array[1]+""+array[2];

there'll probably be a pause when this is executed ... just flash's unbelievably poor text handling characteristics.

good luck.

suprabeener
October 11th, 2001, 02:17 AM
hey, i found a way around it.

if you run this code continously:

if(Selection.getBeginIndex()!=-1){
&nbsp &nbsp &nbsp &nbsp _root.startselect = Selection.getBeginIndex();
&nbsp &nbsp &nbsp &nbsp _root.endselect = Selection.getEndIndex();
}

then use the variables you set instead of the Selection object, you can have the button trigger the text actions. since it won't set them once they equal -1 (ie. if nothing is selected) they'll represent whatever was selected immediately before hitting the button, which is just what we want.

the button code would be:

on(release){
&nbsp &nbsp &nbsp &nbsp outputtext = inputtext.slice(startselect,endselect);
}

i also wrote a function for highlighting text. bold and italic tags result in the surrounded text disappearing (not the fault of this function) but using a font colour instead works fine:

function highlight(string,startpoint,endpoint){
&nbsp &nbsp &nbsp &nbsp var a = new Array();
&nbsp &nbsp &nbsp &nbsp a[0] = string.slice(0,startpoint);
&nbsp &nbsp &nbsp &nbsp a[1] = string.slice(startpoint,endpoint);
&nbsp &nbsp &nbsp &nbsp a[2] = string.slice(endpoint,string.length);
&nbsp &nbsp &nbsp &nbsp return(a[0]+"<font color=\"#ff0000\">"+a[1]+"</font>"+a[2]);
}

then call it (in conjunction with the method of preserving the start and end selects as above):

outputtext = highlight(inputtext,startselect,endselect);

lovely.