5 Replies Latest reply on Jun 18, 2009 7:00 AM by kglad

    count time in millisecond when datagrid load data

    desmodromics

      Hello World,

       

      Im newbie in Flash and ActionScript things.
      I want to counting how long the dataGrid loads all the data.
      I've try his code :

       

      var date1:Date = new Date;

      xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

      xmlLoader.load(new URLRequest("http://localhost/final/Flash/DB-Single/get_db.php"));

       

      var date2:Date = new Date();

      trace( date2.valueOf() - date1.valueOf() );

      trace ( date2.getTime() - date1.getTime() );

      loadTimeTB.text = "Loaded : "+ (date2.valueOf() - date1.valueOf()) +" Milliseconds";

      but the result is 1 or 0 Milliseconds. i think its kinda wierd. because the dataGrid load takes longer than 1 Millisecond.
      anyone can help me? or give me any ideas?

       

      thanks before lads.

       


      -desMO-

        • 1. Re: count time in millisecond when datagrid load data
          Rothrock Level 5

          That is because you are executing the code one right after another. I'm surprised that it ever gets as high as 1.

           

          You need to put the first date right after you execute the load command, which is what you have.

           

          But you need to put the second trace inside the COMPLETE event handling function. Which I see you have assigned, but I don't see where the LoadXML function is called. BTW, it is generally good to start Class names with capital letters, but methods (functions) should start with lower case letters.

           

          I think you can also make it a little easier if you use getTimer() instead of the Date class.

           

          xmlLoader.addEventListener(Event.COMPLETE, loadXML);

          xmlLoader.load(new URLRequest("http://localhost/final/Flash/DB-Single/get_db.php"));

          var startTime:Number=getTimer();

           

          function loadXML(e:Event){

              loadTimeTB.text = "Loaded : "+ (getTimer()-startTime) +" Milliseconds";

          }

          • 2. Re: count time in millisecond when datagrid load data
            desmodromics Level 1

            thanks for bringing up new things in actionscript.

            but im still confuse with actionscript syntax.

             

            here's my full syntax, i just compiled it, still with errors. can you help me which part that I mistaken?

             

            import fl.data.DataProvider;

            import fl.controls.ScrollPolicy;

            import fl.controls.DataGrid;

             

            var xmlLoader:URLLoader = new URLLoader();

            var xmlData:XML = new XML();

            var dp:DataProvider = new DataProvider();

             

            xmlLoader.addEventListener(Event.COMPLETE, LoadXML);

            xmlLoader.load(new URLRequest("http://localhost/final/Flash/DB-Single/get_db.php"));

            var startTime:Number=getTimer();

             

            function LoadXML(e:Event):void

            {

                 xmlData = new XML(e.target.data);

                 //trace(xmlData);

                 var dp:DataProvider = new DataProvider(xmlData);

                 

                 myDataList.removeAllColumns();

                 myDataList.removeAll();

                 myDataList.dataProvider = dp;

                 myDataList.horizontalScrollPolicy = ScrollPolicy.ON;

                 

                 loadTimeTB.text = "Loaded : "+ ( getTimer() - startTimer ) +" Milliseconds";

                 loadTimeTB.autoSize = TextFieldAutoSize.LEFT;

             

            }

             

             

             

            thanks for your time to responding me.

             

            best regards,

             

             

            -desMO-

            • 3. Re: count time in millisecond when datagrid load data
              kglad Adobe Community Professional & MVP

              use the urlloader's progress event to repeatedly update the load duration.  using getTimer() would be more efficient and as informative as using the date class, in this situation.

              1 person found this helpful
              • 4. Re: count time in millisecond when datagrid load data
                desmodromics Level 1

                geezz.... LOL.

                 

                i dunno why, accidently works.

                 

                bunch a thanks you guys for helpin me trough!

                • 5. Re: count time in millisecond when datagrid load data
                  kglad Adobe Community Professional & MVP

                  if that works, it's because you're testing locally or your xml file is small.