Search code examples
actionscript-3apache-flexactionscriptflash-cs5flex4.5

Actionscript 3 - Is it ok to have a bunch of code inside an event listener handler?


I'm creating a GUI, but only if things go ok, so can i

addEventListener(Event.Complete, go) to something and in the go function create my GUI (grafical elements such as labels, lists, squares)?

Is it ok to do that?


Solution

  • Yes that is perfectly fine. The go function isn't part of the event listener.

    function go(e:Event):void {
    // do something
    }
    

    The sample above requires the event parameter from the listener (e:Event).

    But you can modify the function so that the parameter is optional so you can call the go function any time you want

    function go(e:Event = null):void {
    // do something
    }
    

    The example above will be triggered by the listener and also by typing

    go();