topical media & game development

talk show tell print

professional-flex-code-14-TextInputWithCountEvent.ax

professional-flex-code-14-TextInputWithCountEvent.ax [swf] flex


  package
  {
    import mx.controls.TextInput;
    import flash.events.Event;
    
    [Event(name="lengthOf5Event", type="flash.events.Event")]
    [Event(name="lengthOf10Event", type="flash.events.Event")]
    public class @ax-professional-flex-code-14-TextInputWithCountEvent extends TextInput
    {
      private var _myText:String;
      private var eventObj:Event;
      
      public function set myText(s:String):void{
        _myText = s;
        this.text=s;
        if(s.length==5){
          // Create and dispatch custom event
                eventObj = new Event("lengthOf5Event");
                dispatchEvent(eventObj);
        } else if (s.length==10){
          eventObj = new Event("lengthOf10Event");
                dispatchEvent(eventObj);
        }
      }
    }
  }


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.