views:

62

answers:

3

How do I get Set Selection to work in a text field. I have a text field inside a movieclip and a button with a click listener on it. When it clicks I want it to select all the text inside. This is what I have so far, I hope you can help.

send.addEventListener(MouseEvent.CLICK, function() {
    panel.tweet.selectable = true;
    stage.focus = panel.tweet;
    panel.tweet.setSelection(0, panel.tweet.text.length);
});
A: 

Try doing it this way: (I don't have Flash right now to test...)

send.addEventListener(MouseEvent.CLICK, function() {
    panel.tweet.selectable = true;
    panel.tweet.stage.focus = panel.tweet;
    panel.tweet.setSelection(0, panel.tweet.text.length);
});

If it's not this, then it could be the mouseup event that's clobbering the highlight.(?)

Andir
Unfortunatly, I tried it and it doesn't work, thank you though
Patrick Gates
+1  A: 

Crazy - should work fine.

I made a little demo for you to see it working:

http://strangemother.com/actionscript/demos/select_text_click_demo/

import flash.events.MouseEvent;

send.addEventListener(MouseEvent.CLICK, sendMouseClickEventHandler);

function sendMouseClickEventHandler(ev:MouseEvent):void
{
    stage.focus = tweet;
    tweet.selectable = true;
    tweet.setSelection(0, tweet.text.length ); 

}
Glycerine
I found the problem, it's CS5, the new TLF text doesn't support this feature, thank you adobe, for confusing me, once again, Thank you guys for the help, greatly appreciated
Patrick Gates
A: 

Your code should work, I think.

Is the event listener being called at all?

Maybe there's some movieclip over it that blocks your send button (it could be transparent and you might not realize it's there).

A quick and dirty way to check if that's the problem:

send.stage.addChild(send);

This will place your button on top of every object. If your handler was not called and after doing that gets called, you can be pretty sure there's something blocking it. If that case, you could re-arrange depths or try setting blocking movieclips mouseEnabled property to false. mouseChildren could also help if said movieclips contain in turn other blocking objects (that don't need to react to mouse events, of course).

Juan Pablo Califano
It's definitely being called, so I'm going to work on it some-more
Patrick Gates