6 Replies Latest reply on Mar 24, 2009 5:28 AM by Newsgroup_User

    Return statement inside AddEventListener?

    Jurgen_Beliën
      I am writing a custom function that will add a component to the stage. However, I want to postpone adding this component until some data has been loaded. Problem is that placing the return statement inside the Event handler function won't work, because it would be interpreted as a return statement for the Event handler function. Is there a way to for instance refer to the parent function?
        • 1. Re: Return statement inside AddEventListener?
          LPVOID32 Level 1
          hi
          inside the complete Event handler function ,you can use "event.currentTarget" to refer to the drawerContentLoader.
          • 2. Return statement inside AddEventListener?
            Jurgen_Beliën Level 1
            Yes, but what I want to do is to make the main function return newDrawer after the drawerContentLoader is finished loading. I fail to see how referring to the drawerContentLoader inside the Event handler helps me with that.
            • 3. Re: Return statement inside AddEventListener?
              Gregory Lafrance Level 6
              Instead of returning newDrawer, pass it to a function.
              • 4. Re: Return statement inside AddEventListener?
                Level 7

                "Jurgen Beli?n" <webforumsuser@macromedia.com> wrote in message
                news:gq7jbs$7i4$1@forums.macromedia.com...
                >I am writing a custom function that will add a component to the stage.
                >However,
                > I want to postpone adding this component until some data has been loaded.
                > Problem is that placing the return statement inside the Event handler
                > function
                > won't work, because it would be interpreted as a return statement for the
                > Event
                > handler function. Is there a way to for instance refer to the parent
                > function?
                >
                > private function addDrawer(...):Drawer {
                > var newDrawer:Drawer = new Drawer();
                >
                > drawerContentLoader.addEventListener(Event.COMPLETE, function
                > (event:Event):void {
                > newDrawer.DrawerContentXml = XML(drawerContentLoader.data);
                >
                > // return newDrawer when loaded.
                >
                > });
                > drawerContentLoader.load(drawerContentRequest);
                >
                > return newDrawer;
                > }

                Why not just put your logic inside the handler for the event where the data
                exists for you to actually be able to populate it?


                • 5. Re: Return statement inside AddEventListener?
                  LPVOID32 Level 1
                  I got your point , but sorry you can not apply it
                  because events are asynchronous , i mean you register to an event with a callback function that will be invoked when the event is fired.
                  even if you think about checking the event inside a loop within the event listener function you will get a time out error
                  • 6. Re: Return statement inside AddEventListener?
                    Level 7

                    "LPVOID32" <webforumsuser@macromedia.com> wrote in message
                    news:gq9nmr$su4$1@forums.macromedia.com...
                    >I got your point , but sorry you can not apply it
                    > because events are asynchronous , i mean you register to an event with a
                    > callback function that will be invoked when the event is fired.
                    > even if you think about checking the event inside a loop within the event
                    > listener function you will get a time out error

                    No, I meant MOVE the logic that's causing the problem to a place where it is
                    not causing a problem.
                    :exasperated