You're not missing anything. The fact that we provided a way for you to
cancel text insertion but not text deletion is a design omission in the
textInput event. I've filed a bug with the Player team, but given the
schedule it may not get fixed.

However, I think workarounds are possible. Here is some code that
demonstrates that you can restore the old text and the old selection--
without flashing -- after both insertion and deletion.

Run it, click in the text and then try typing characters or pressing
Delete and Backspace. Nothing changes because I use the change event to
restore the text and the selection back to the values they had at the
textInput event.

Try adapting this technique to your needs.

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" width="600"
height="600">

      <mx:Script>
      <![CDATA[

            import mx.core.mx_internal;
           
            private var savedText:String;
            private var savedCaretIndex:int;
           
            private function textInputHandler(event:TextEvent):void
            {
                  savedText = ti.text;
                  savedCaretIndex =
ti.mx_internal::getTextField().caretIndex;
            }

            private function changeHandler(event:Event):void
            {
                  ti.text = savedText;
                  ti.setSelection(savedCaretIndex,
savedCaretIndex);
            }

      ]]>
      </mx:Script>

      <mx:TextInput id="ti" text="Gordon"
textInput="textInputHandler(event)" change="changeHandler(event)"/>

</mx:Application>

- Gordon



-----Original Message-----
From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Steven Toth
Sent: Thursday, May 18, 2006 8:49 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: How to cancel Keyboard events?

I'm writing a masked edit control.  I want to do various things at
various times.  I want to allow the deletion of certain characters. 
I want to allow editing of certain characters.  All of which is
dependent on the keyboard event/text input, mask, caret index, and
selection begin/end index.  The textInput event works perfectly.  My
issues center around trapping and ultimately rejecting (under
certain cirucmstances) keyboard events for keys such as DELETE,
BACKSPACE, LEFT, RIGHT, etc.  I already have some code to workaround
not being able to cancle the LEFT and RIGHT Keyboard events, but it
doesn't look all that nice (you see the caret move and then move
back). 

Thanks for the suggestions.  However, I don't think what I'm trying
to do is all that unusual.  I've done it in numerous other languages
and I don't think I should have to write excessive amounts of code
to store and restore state when the same thing could be accomplished
by having the appropriate control over the events.  It seems like
either I'm missing something or the language is.  

Thanks again.  The suggestions are greatly appreciated.

-Steven

--- In flexcoders@yahoogroups.com, "Chris Velevitch"
<[EMAIL PROTECTED]> wrote:
>
> On 5/19/06, Steven Toth <[EMAIL PROTECTED]> wrote:
> > No dice.  I do see the eventPhase equal to 1 (capture), but the
> > stopPropagation() and stopImmediatePropagation() still do not
> > prevent the DELETE from being processed.  I'm beginning to think
I'm
> > just going about this the wrong way.  There has to be a way to do
> > this.
>
> As I understand it, capture only works for the container containing
> the text field, that is before the target gets it.
>
> And alternative would be to save the state of the text field and if
> the length is zero use the saved state to restore it. I'm assuming
you
> want to prevent all the data from being deleted and but allow it
to be
> edited.
>
>
> Chris
> --
> Chris Velevitch
> Manager - Sydney Flash Platform Developers Group
> www.flashdev.org.au
>








--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives:
http://www.mail-archive.com/flexcoders%40yahoogroups.com
Yahoo! Groups Links









--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




Reply via email to