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){
        if (Key.getCode() == Key.ENTER) {
                _root.outputtext = _root.inputtext.slice(Selection.getBeginIndex(),Se lection.getEndIndex());
                trace(_root.inputtext);
        }
}
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){
        _root.startselect = Selection.getBeginIndex();
        _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){
        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){
        var a = new Array();
        a[0] = string.slice(0,startpoint);
        a[1] = string.slice(startpoint,endpoint);
        a[2] = string.slice(endpoint,string.length);
        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.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.