5 Replies Latest reply on Jun 3, 2009 6:29 PM by kglad

    Shared object causing Flash application to crash

    schuel2

      I have a couple of static functions (one shown below) that can be called from multiple instances; there is a problem because of a shared object I am using.

       

      My tracing shows that the application is in this function or the converse function addRec when my application is crashing.

       


          public static var currentRecs:Array;

       


          private static function removeRec(recName:String) {
              trace("Removing record "+ recName + " from currentRecs");
              for (var item in currentRecs) {
                  if (currentRecs[item] == recName) {
                      currentRecs.splice(item, 1);
                      trace("Finished recording " + recName + " currentRecs = " + currentRecs.length);
                  }
              }
          }

       

      In another class I have this statement where I set the value of some date in my shared object. I have to comment the following lone of code out in order for the application not to crash after a short while:

       

          so.data.rArray = currentRecs;          // the culprit

      I see the first trace in the removeRec function but then nothing. I expect to see the second trace indicating that the array of current recordings taking place (currentRecs) has been cut back by one.

       

      Originally my function was not static and my application crashed very quickly. By making the function static the situation improved insofar as it took longer for the application to crash.


      Flash seems to be very particular about the way it handles shared objects.

       


      David

        • 1. Re: Shared object causing Flash application to crash
          kglad Adobe Community Professional & MVP

          iterate through currentRecs from its last index to its first.

          • 2. Re: Shared object causing Flash application to crash
            schuel2 Level 1

            The two functions I have are now

             


            private static function removeRec(recName:String) {
                    var rIndex:Number = -1;
                    for (var i:Number = 0; i<Common.currentRecs.length; i++) {
                        if (Common.currentRecs[i] == recName) {
                            rIndex = i;
                            break;
                        }
                    }
                    if (rIndex != -1) {
                        Common.currentRecs.splice(rIndex,1);
                    }
                    Common.recArray = Common.currentRecs;
                }

             


                private static function addRec(recName:String) {
                    Common.currentRecs.push(recName);
                    for (var item in Common.currentRecs) {
                        mApplication.trace("Now recording " + Common.currentRecs[item]);
                    }
                    Common.recArray = Common.currentRecs;
                }

             


            and in another class at another time I set the shared object with

             


                    Connection.so.data.rArray = Common.recArray;

             


            The shared object works for a little while i.e.about 10 minutes which involves 10 times the shared object is updated.  That is to say that I get information from the RecArray successfully passed to my client.

             


            And then the application crashes. The last trace statement was just before the code gets to the splice statement in the removeRec function.

             

            I tried the reverse iteration in the removeRec but couldn't see any reason with the way I have restructured the functions that it would make any difference and it didn't. In fact it was worse - the application crash happened very quickly after I had launched the application.

            • 3. Re: Shared object causing Flash application to crash
              kglad Adobe Community Professional & MVP

              what purpose does Common.recArray serve?  ie, there's probably no reason for it to exist or you're making changes to it thinking those changes will not affect Common.currentRecs (which is incorrect).

               

              also, using the trace function, exactly where does your app crash?

              • 4. Re: Shared object causing Flash application to crash
                schuel2 Level 1

                Thanks for your help but I have ended giving up on this apprpoach. It turns out that I am able to provide the same functionality by other means.

                 

                David