Copy link to clipboard
Copied
Someone know Know How to disable copy/paste inside Flex InputText control?
I have Flex 3.2 SDK.
Thanks
Copy link to clipboard
Copied
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
Copy link to clipboard
Copied
Hi,tomaugerdotcom !
I found that it is not right.I think it can't achieve the desired effect by experiment.If the user use the right mouse button to paste or use "Ctrl + V" that will not be able to capture "TextEvent. TEXT_INPUT".
I have flex 4.5 SDK.
Thanks.
Copy link to clipboard
Copied
private var oldTxt:String="";
protected function txtIpt_changeHandler(event:TextOperationEvent):void
{
var s:String=(event.currentTarget as TextInput).text;
var n:Number=Number(s);
if(!isNaN(n))
{
var newS:String=s.substring(oldTxt.length,s.length);
if(newS.length>1)
{
txtIpt.text=oldTxt;
}else
{
txtIpt.text=s;
}
}else
{
txtIpt.text=oldTxt;
}
oldTxt=txtIpt.text;
trace(txtIpt.prompt);
}
myTextInputField.addEventListener(TextOperationEvent.CHANGE, txtIpt_changeHandler);
You can use this method!
Get ready! An upgraded Adobe Community experience is coming in January.
Learn more