2 Replies Latest reply on Apr 11, 2008 11:55 AM by bre358

    Source Code Wrong in a Book

      Recently I started learning Flex 3 for a project I plan to begin at work. The book I bought over Amazon.com was amazingly informative and useful. That said, I noticed one or two Source code listings which apparently throw errors or warnings even when copied verbatim without the edits I usually make to consolidate a few code samples into better reference tools for myself. I've been having trouble figuring out what is exactly wrong with the code, but that's not surprising since I've only been learning Flex for a few days at this point. Here's a code sample I found to be wrong yet I could not figure out why:
      Code Snippet 1
        • 1. Re: Source Code Wrong in a Book
          camfieldaj Level 1
          looks like you're nesting functions; Is this what you meant to do.

          function initApp():void
          button1.addEventListener(MouseEvent.CLICK, customEventHandler);

          function customEventHandler(event:Event):void
          Alert.show("The Mouse has been clicked.");

          Also, since you declared the click handler function in the button declaration , you don't need to do the addEventListener.


          Andy C.(never #)
          • 2. Re: Source Code Wrong in a Book
            bre358 Level 1
            Thanks, it took me a moment to figure out your answer, I was being thrown off by how the code you put in was not indented. But I fixed the program by simply moving the customEventHandler function outside. And of course I no longer needed the addEventListener.