5 Replies Latest reply on Nov 9, 2009 3:32 PM by SHevenal776

    What's the OnLoad event

    barryman9000

      I'm new to Flex so this is probably a total noob question, but how can I call a function when the swf loads?  I'm looking for the Flex equivalent of Page_OnLoad (ASP.NET) or the JS equivalent of Window.onload()... something like that.

       

      Thanks

        • 1. Re: What's the OnLoad event
          msakrejda Level 4

          The Application (or rather, your top-level class, which extends Application) dispatches FlexEvent.APPLICATION_COMPLETE once it is finished loading.

          1 person found this helpful
          • 2. Re: What's the OnLoad event
            barryman9000 Level 1

            OK, thanks.  I think I got it by using the creationComplete property of the <mx:Application /> control, but if there is a better way of doing this I wouldn't mind some help.

             

             

            <mx:Application creationComplete="loadServiceResult()" />

             

            //runs when swf is loaded

            private function loadServiceResult():void

            {

              //runs all the webservice code which is bound to a dataGrid

            }

            //runs when button is clicked

            private function clickHandler(event:MouseEvent):void

            {

               loadServiceResult();

            }

            • 3. Re: What's the OnLoad event
              msakrejda Level 4

              That's another event you can use--it sort of depends on how "finished" you need the loading to be when your event handler executes. Typically, applicationComplete is the "last word" on initialization of your app--I think it runs somewhat *after* creationComplete--but this may not really make a difference in your case. In fact, if you're doing something like trigerring web services, you may want to do that *before* the application is done loading (e.g., preInitialize) to allow some application initialization and web service execution to complete in parallel.

              • 4. Re: What's the OnLoad event
                SHevenal776

                Hi, you can do this by including a line similar to this in your app

                header (note the "creationComplete" item):

                 

                <?xml version="1.0" encoding="utf-8"?>

                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

                 

                creationComplete="yourFunctionHere!()"

                 

                viewSourceURL="srcview/index.html"

                1 person found this helpful
                • 5. Re: What's the OnLoad event
                  barryman9000 Level 1

                  Great, thank you both!