1 Reply Latest reply on Jun 5, 2006 2:27 PM by blemmo

    Basic Button Component help

      The button is described here:

      http://livedocs.macromedia.com/flash/mx2004/main_7_2/wwhelp/wwhimpl/common/html/wwhelp.htm ?context=Flash_MX_2004&file=00002093.html#3647770

      I'm trying to port in a custom function to handle the clicking of this button. The code associated iwth this page is very confusing to me.

      function click(evt){
      clippyHelper.enabled = evt.target.selected;
      helpBtn.addEventListener("click", this);

      I don't understand what the significance of "clippyHelper" is. I don't know if that line is nessicary. No where does the page explain teh sendding of "click" or this....

      someone commented an easier way to do the click handling, but a site admin said it was not correct w/ out any follow up.

      I feel retarted for having to ask, but no one wants to break this down anywhere....
        • 1. Basic Button Component help
          blemmo Level 1
          The components have built-in event dispatchers, in the case of a button it is the 'click' event. This gets broadcasted when the button is clicked; you don't need to write any code for that, it's contained in the components.
          Now the code you posted sets up a listener to this event. A listener is an object that defines a function with the same name as the event it should listen too. In this example, there's no extra object used, instead it uses the timeline (which is also an object). It defines the 'click' function on the timeline and passes this (timeline) in the addEventListener method. It could also be done like this:
          var listenerObject:Object = new Object();
          listenerObject.click = function(eventObj:Object){
          // ...
          buttonInstance.addEventListener("click", listenerObject);
          Maybe this makes clearer what's going on.

          The 'clippyHelper' is only an example for an MC that gets enabled or disabled on a button click. Because it's a toogle button in the example, the _enabled property of the MC is bound directly to the 'selected' property of the button. You can get to the object which fired the event via the 'evt.target' parameter.

          So you can just delete that line and place your own code there.