2 Replies Latest reply on Dec 29, 2011 7:47 AM by pbesi

    dispatchEvent statement not recognized in external .as source file



      I've a .mxml file.

      Inside it a button tag, and the related click event method handler.

      Obviously the method is inside the <fx:script> tag. It works!! Nice!


      The handler method is:


      protected function loginButton_clickHandler(event:MouseEvent):void
                var user:User = new User(username.text, password.text);
              dispatchEvent(new LoginButtonEvent(user)); 


      Now I want to put my code in a external .as file. Reading the documentation, I've to write:


      <fx:script source = "path/externalFile.as">



      The method inside the external .as file is the same above and not included in any class or something else. Just the method as you see above.


      Flash Builder says that dispatchEvent is a call to an undefined function!! I tried also to write the syntax "mx.core.UIComponent.dispatchEvent". No way!

      I've also tried to embed the code inside an XML CDATA statement but, as I was expecting CDATA is not accepted in such configuration. It is an XML statement.


      If I comment the dispatchevent, everything works.


      Please, can anyone clarify where is the problem?


      Reading the documentation I see that writing the code inside <fx:script> or working with its source attribute is the same, but...

      This is not the first time I've a similar problem.


      Am I wrong? Where?


      Thank you