Solved

Flex TextInput

Posted on 2010-11-17
4
1,391 Views
Last Modified: 2012-05-10
How to restrict a TextInput feild from cut copy and paste?
0
Comment
Question by:srujanmiryala
  • 2
4 Comments
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34161147
So you just want to write but not cut copy and paste?

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com
0
 
LVL 17

Expert Comment

by:deepanjandas
ID: 34161153
I have not tried it but why do you try this one:

On de-focus of te component disable the text field.
try overriding the key press events for cut copy and paste for the text filed (not sure if you can override, which also check this out)

Warm Regards
Deepanjan Das
http://deepanjandas.wordpress.com 
0
 
LVL 14

Accepted Solution

by:
tomaugerdotcom earned 500 total points
ID: 34164749
There are a number of options, depending on what you want to do.

If you want to use the TextInput field to display text but NOT to allow the user to edit the text, set the enabled property to false:
<s:TextInput width="175" enabled="false" text="Sample text..." />

Alternatively, if you want to prevent the user from selecting and copying the text set the selectable property to false:
<s:TextInput width="175" selectable="false" text="Sample text..." />

Finally, if you want to prevent pasting into the area, then we have to trap for the Text event. Basically you're looking to see if someone enters more than 1 letter at a time. If so, don't allow it. The reason this works is that when you're typing, each letter fires the event, but if you're pasting, the entire paste operation triggers the event and that would have more than one letter. Of course, if the person wants to paste one letter at a time, this solution will not prevent that...

private function onTextInput(event:flash.events.TextEvent):void
{
  if (event.text.length > 1)
    event.preventDefault();
}

myTextInputField.addEventListener(TextEvent.TEXT_INPUT, onTextInput);

Hope this helps!

T
0
 

Author Closing Comment

by:srujanmiryala
ID: 34164985
Hello tomaugerdotcom,

Thank you very much for the solution. I am using flex 3.0.
so for  textinput selectable property is not there.
i have went with your script code. it worked fine and that helped me a lot with the solution.

Thank you very much.
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Advanced Datagrid with checkbox 4 306
Video Playback in Flex Mobile App 4 1,496
google maps with flash 1 380
Is HTMLLoader class supported on Flash Player runtime for browser deployment? 3 1,098
First things first - Preparation We need all the part for this install and it's much nicer to have them all on hand when you need them so here's what's required. Download Eclipse 3.5 32 bit (I like the Classic flavour) from here. (http://www.e…
An article on effective troubleshooting
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question