Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Use of the Selection object 1

Status
Not open for further replies.

TheJhereg

Programmer
Nov 12, 2001
31
US
I'm not in a big hurry on this one, but if you've used it, let me know....

I'm trying to use the selection object to grab the text selected in a input text box and set a dynamic text box with the selected text when a button is clicked.

the setup is really simple...

1 input text box, with random text, variable named "TextField1"
1 dynamic text box, variable named "TextField2"

1 button with the following action script:

on(release) {
var objSel = Selection.getFocus()
trace(objSel) ;
var begin = Selection.getBeginIndex() ;
trace(begin) ;
var end = Selection.getEndIndex() ;
trace (end) ;
TextField2 = objSel.slice( begin, end ) ;
}

trace reports : null, -1 -1

I know I've got to be using this wrong... anyone played with the selection object before and gotten it to work? The Jhereg
=~=~=~=~=~=~=~=~=~=~
I never lie.
I'm building a reputation for honesty so I can blow it when something big comes along... This ain't it.
 
If anyone's interested, this code almost works... Problem is when you go to click a button, you remove the selection focus from the input box. The only way I could get this to work was to add another 5 frames and another keyframe at the end, and place the following code in the keyframe itself.


var objSel = Selection.getFocus()
var begin = Selection.getBeginIndex() ;
var end = Selection.getEndIndex() ;
TextField2 = TextField1.slice( begin, end ) ;

I never could get the objSel to give me the variable, it appears to contain the NAME of the variable (level0.TextField1) but not a legitimate reference to it.

I tried separating the text and buttons into different movie clips, but it still removed focus.

Again, if you have any ideas how to do this in response to a button click, lemme know.
The Jhereg
=~=~=~=~=~=~=~=~=~=~
I never lie.
I'm building a reputation for honesty so I can blow it when something big comes along... This ain't it.
 
So what are you really looking for?
You did get to display the selection in Textfield2? And now your aim is not to loose focus or not loose the highlighted area in TextField1, when displaying TextField2?

Regards,
wink4.gif
ldnewbie
 
The actual aim is to select text in one box, press a button, and have that text appear in a second (or be used in another control).

I'm not sure it's a realistic aim, but it'd be nice. The Jhereg
=~=~=~=~=~=~=~=~=~=~
I never lie.
I'm building a reputation for honesty so I can blow it when something big comes along... This ain't it.
 
I've done that... But understood that you had too!
Thought you were only now preoccupied by maintening the selection in the input field (which looses focus, thus the selection!) once that button is hit.
I can post an example if you're only looking to display the selected text, and don't care about the selection disappearing in the input field, once it's displayed in the display field.

Regards,
wink4.gif
ldnewbie
 
Oldnewbie, that'd be great!!

Up to this point, the only way I could make it work was to capture it in a frame action... If you know a way to capture selection in a button action, I'd name my first child after ya ;-)


The Jhereg
=~=~=~=~=~=~=~=~=~=~
I never lie.
I'm building a reputation for honesty so I can blow it when something big comes along... This ain't it.
 
Cleaning up what I've got...
Will post it a little later, if not in the morning!
Hope it's really what you're looking for and that I've understood you correctly!

As for child naming, hold your promises (I've already been promised things... And I'm still waiting!), anyway, oldnewbie is not a child's name!

Regards,
wink4.gif
ldnewbie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top