3 Replies Latest reply on Nov 3, 2009 1:30 PM by TodLoch

    Problem with dispatching events.

    TodLoch Level 1

      Hello,

       

      I have some problem with dispatching, or maybe executing events.

       

      I have function assigned with event "click" on my button. In this function I have a loop "for" in which I dispatch my own event (CairngormEvent).

      This is a part of the function:

       

      <mx:Button ... click="konw()" />

      ....

      public function konw():void

      {

      ......


           for (var i in "array collection")

           {

                     .....

                     //here is some code which populate the object "client" with data

       

                     var event:MyCairngormEvent = new MyCairngormEvent();

                     //this event "sends" object "client" to HTTPService which call "somefile.php" and insert data into MySQL database

       

                     event.data = "some string";

                     event.dispatch();

           }

      }

       

      I have 2 questions:

       

      1) Why the event isn't process during looping?, all events are collected and are processed after code execution goes out the function know()

      2) The loop repeats abour 6000 times, but I can write to database only about 350 "clients", and the inserting to databases stops. When I reduce the number of looping under 350, it works, but increasing number of loop up to about 400 stops inserting clients again. What could be the reason? How to force inserting data into databases in for statement, not after exiting the function konw() ?

       

      Best regards

        • 1. Re: Problem with dispatching events.
          paul.williams Level 4

          Flash won't actually make the server calls until after all your pending event handlers have completed. Even if it did make the calls immediately it wouldn't be sensible to make 6000 calls to the server in response to a single mouse click. Aim for a maximum of one server call per user gesture and design your server to support this.

          • 2. Re: Problem with dispatching events.
            TodLoch Level 1

            Problem with dispatching events inside loop I solved in this way: I change loop "for"  on Timer object with function which handle TIMER event.

             

            was:

            for (var i:String in "array collection")

            {

             

            }

             

             

            is:

            var myTimer:Timer = new Timer(100, "array collection".length() );

            myTimer.addEventListener("timer", timerHandler);

            myTimer.start();

             

            public function timerHandler()event:TimerEvent):void

            {

                 //here code from loop "for"

            }

             

             

            :-)

            • 3. Re: Problem with dispatching events.
              TodLoch Level 1

              Paul, thaks for your reply,

               

              This single click starts the conversion process. There is ~6000 row in each of seven xml files, which I take to create "client" object and send it to the database. I change the "for" loop on Timer object, as I have posted just now. It seems to work.