Skip to main content
November 19, 2009
Question

Passing extra argument in event listener?

  • November 19, 2009
  • 2 replies
  • 851 views

Is this possible?  I have one event handler for several object's events.  I would like to pass a value through to the function from the event listener:

 function chkEmpty(event:Event){
               if(event.currentTarget.text==""){
                    thisIsBitIWantToBeAbleChange.text = "You haven't entered anything in the box, please try again"
                    hisIsBitIWantToBeAbleChange.setTextFormat(validate_frmt);
               }
          }

Could I give the event.currentTarget a value that I could test for? So if the value is 1, I effect output1_txt, if 2, output2_txt, etc etc. If so, are there customisable values that I could use that wouldn't do anything to the display object,?

This topic has been closed for replies.

2 replies

Goshine
Inspiring
November 20, 2009

ok  you need to mark this as answered

November 19, 2009

Sorry, I can't work the code highlighting things on here!

Here is my problem again:

Is this possible?  I have one event handler for several object's events.  I would like to pass a value through to the function from the event listener:

function chkEmpty(event:Event){
               if(event.currentTarget.text==" "){
                    thisIsBitIWantToBeAbleChange.text = "You haven't entered anything in the box, please try again"
                    hisIsBitIWantToBeAbleChange.setTextFormat(validate_frmt);
               }
          }

The event listener is on various textInput boxes.  It is called when it loses focus.

Could I give the event.currentTarget a value that I could test for? So if the value is 1, I effect output1_txt, if 2, output2_txt, etc etc. If so, are there customisable values that I could use that wouldn't do anything to the display object,?

Goshine
Inspiring
November 20, 2009

Is this what you After?  you can use the propertist of your  event.target to make decisions

btn1.addEventListener(MouseEvent.CLICK,chkEmpty);
btn2.addEventListener(MouseEvent.CLICK,chkEmpty);
btn3.addEventListener(MouseEvent.CLICK,chkEmpty);
function chkEmpty(evt:Event) {


     if (evt.currentTarget.name=="btn1") {


          trace( "You haven't entered anything in the box, please try again");
     } else if (evt.currentTarget.name != "btn1") {
          trace( evt.currentTarget.name);
     }
}

November 20, 2009

does name refer to the var name the object is contained?