Solved

Flex TextInput

Posted on 2010-11-17
4
1,397 Views
Last Modified: 2012-05-10
How to restrict a TextInput feild from cut copy and paste?
0
Comment
Question by:srujanmiryala
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Raise the IQ of Your IT Alerts

From IT major incidents to manufacturing line slowdowns, every business process generates insights that need to reach the people required to take action. You need a platform that integrates with your business tools to create fully enabled DevOps toolchains.

You need xMatters.

Question has a verified solution.

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

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…
Make the most of your online learning experience.
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…

717 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