1 Reply Latest reply on Mar 4, 2009 4:16 AM by Ned Murphy

    Checkbox Event Handlers

    izdo89 Level 1
      I'm trying to make it so that when the viewer clicks on a checkbox, the value of a Text Input Field changes. This is the code I have so far:

      theNews.onPress = function(){
      if(newsText.text == "No"){
      newsText.text = "Yes";
      }
      if(newsText.text == "Yes"){
      newsText.text = "No";
      }
      }

      theNews is the checkbox and newsText is the Text Input Field. I've previously set newsText.text to "No". However, when I preview the movie, when I click on the checkbox it has no affect on the newsText.text. Can anyone help?
        • 1. Checkbox Event Handlers
          Ned Murphy Adobe Community Professional & MVP
          You should make use of the Flash help docs. There are examples of this in there. Also, your code will not produce any change unless things start out as "Yes" for the textfield. As is it would change to "No" on the first click and then never appear to change back to "Yes"

          var checkboxListener:Object = new Object();

          checkboxListener.click = function(evt_obj:Object) {
          if(newsText.text == "No"){
          newsText.text = "Yes";
          } else if(newsText.text == "Yes"){
          newsText.text = "No";
          }
          }

          theNews.addEventListener("click", checkboxListener);