[Flashcoders] setSelection() with TextInput?
Hi all. I've been beating my head against the wall for a bit, trying to get Selection.setSelection() to work inside a component. I've got this code, inside a component which happens to contain a TextInput: private function focusIn(){ trace(answer_ti.text + ] received focus); answer_ti.setFocus(); Selection.setSelection(0, answer_ti.text.length); } Which gets runs when answer_ti fires a focusIn event. This just doesn't seem to work... the trace statement comes up, but I can't see the selection change. Is there anything I've overlooked? I tried to use Delegate for event handling, but it didn't make a difference. Thanks. -- Haikal Saadh Applications Programmer ICT Resources, TALSS QUT Kelvin Grove ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] setSelection() with TextInput?
Hi Haikal, I've just been doing exactly the same thing for the past day - beating my head against the wall for this same reason. I am not working with any components, but trying to use setSelection within a class to select text in a text field nested within a movieClip - and getting the same non-result. Infuriating. So, what I finally came up with that is a lame hack but seems to work is using a setInterval to call setSelection a tenth of a second later. So basically it's this: class myClass { ... (var declarations, constructor, etc.) ... private function onMouseUp ():Void { clearInterval(selectionRunner); selectionRunner = setInterval(this, selectString, 10); } private function selectString () { clearInterval(selectionRunner); Selection.setFocus(myField_txt); Selection.setSelection(0, myField_txt.text.length); } ... (mode methods, etc.) ... } If anyone else has a better solution (or even better, an explanation why this problem occurs in the first place) I'd love to hear it. Cheers, -DB Hi all. I've been beating my head against the wall for a bit, trying to get Selection.setSelection() to work inside a component. I've got this code, inside a component which happens to contain a TextInput: private function focusIn(){ trace(answer_ti.text + ] received focus); answer_ti.setFocus(); Selection.setSelection(0, answer_ti.text.length); } Which gets runs when answer_ti fires a focusIn event. This just doesn't seem to work... the trace statement comes up, but I can't see the selection change. Is there anything I've overlooked? I tried to use Delegate for event handling, but it didn't make a difference. Thanks. -- Haikal Saadh Applications Programmer ICT Resources, TALSS QUT Kelvin Grove ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com
Re: [Flashcoders] setSelection() with TextInput?
Aha! That gives me an idea... I might try using doLater(), a method available to components and see if that works. Thanks for the tip. David Baldeschwieler wrote: Hi Haikal, I've just been doing exactly the same thing for the past day - beating my head against the wall for this same reason. I am not working with any components, but trying to use setSelection within a class to select text in a text field nested within a movieClip - and getting the same non-result. Infuriating. So, what I finally came up with that is a lame hack but seems to work is using a setInterval to call setSelection a tenth of a second later. So basically it's this: class myClass { ... (var declarations, constructor, etc.) ... private function onMouseUp ():Void { clearInterval(selectionRunner); selectionRunner = setInterval(this, selectString, 10); } private function selectString () { clearInterval(selectionRunner); Selection.setFocus(myField_txt); Selection.setSelection(0, myField_txt.text.length); } ... (mode methods, etc.) ... } If anyone else has a better solution (or even better, an explanation why this problem occurs in the first place) I'd love to hear it. Cheers, -DB Hi all. I've been beating my head against the wall for a bit, trying to get Selection.setSelection() to work inside a component. I've got this code, inside a component which happens to contain a TextInput: private function focusIn(){ trace(answer_ti.text + ] received focus); answer_ti.setFocus(); Selection.setSelection(0, answer_ti.text.length); } Which gets runs when answer_ti fires a focusIn event. This just doesn't seem to work... the trace statement comes up, but I can't see the selection change. Is there anything I've overlooked? I tried to use Delegate for event handling, but it didn't make a difference. Thanks. -- Haikal Saadh Applications Programmer ICT Resources, TALSS QUT Kelvin Grove ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com -- Haikal Saadh Applications Programmer ICT Resources, TALSS QUT Kelvin Grove ___ Flashcoders@chattyfig.figleaf.com To change your subscription options or search the archive: http://chattyfig.figleaf.com/mailman/listinfo/flashcoders Brought to you by Fig Leaf Software Premier Authorized Adobe Consulting and Training http://www.figleaf.com http://training.figleaf.com