A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: textbox OnChange in AS3.0 not work?

  1. #1
    Junior Member
    Join Date
    Aug 2009
    Posts
    17

    textbox OnChange in AS3.0 not work?

    Code:
    txt1.addEventListener(Event.CHANGE, setText);
    
    function setText(e:Event):void {
       txt3.text="changed";
    }

    but I tried and did not work, txt3 is never set as changed, see if I put txt1.Text = "test" should automatically trigger the listen but it does not happen ever. I do not know where is the problem?!

  2. #2
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    As I recall "setting" text doesn't trigger it only triggers on user interaction. Not sure what the fix is though

  3. #3
    KoolMoves Moderator blanius's Avatar
    Join Date
    Jul 2001
    Location
    Atlanta GA
    Posts
    5,244
    You could try dispatching the event when you change the text yourself
    dispatchEvent(new Event(Event.CHANGE, true));

  4. #4
    Junior Member
    Join Date
    Aug 2009
    Posts
    17
    Thanks, I think I'll have to study to develop custom events then.

  5. #5
    up to my .as in code Chris_Seahorn's Avatar
    Join Date
    Dec 2004
    Posts
    4,389
    It works fine for user entered text...

    txt1.addEventListener(TextEvent.TEXT_INPUT, setText);

    function setText (e:TextEvent):void {
    txt3.text="changed";
    }

    But what you ask for is an oddity IMO. If you are programtically setting the text, the need for a text change listener is moot anyway as you KNOW you are changing the text (after all you wrote the code to set it) and would (I would assume) also add code to notify whatever needs to be notified that you have set it. A listener makes sense (and I assume Actionscript is setup this way as it relates to text change events) only when you need to detect text entered in a way you could not possibly forsee or when they might do so (for instance the end user entering something at any given time). In your case you KNOW when you are setting it so it's odd you would need to detect that as it is initiated by your code. Making sense?

  6. #6
    Junior Member
    Join Date
    Aug 2009
    Posts
    17

    resolved Resolved

    Chris_Seahorn, Magnificent thus worked very well. Thanks for your help.

  7. #7

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center