5 Replies Latest reply on Mar 30, 2010 9:19 AM by kglad

    A question about object's life time!

    xhdreamlover-VT8xt5

      My first .fla file like this:

       

      Layer1: label ->"animation";  frame1(key frame) -> a movie clip, its instance name is "mcTest";

      Layer2: label ->"as"; frame1(key frame) -> trace(mcTest); frame2(key frame) -> trace(mcTest);

       

      The output is :

      _level0.mcT

      undefined

       

       

       

      Then i modify the .fla to this:

      Layer1: label ->"animation";  frame1(key frame) -> a movie clip, its instance name is "mcTest";

      Layer2: label ->"as"; frame1(key frame) -> var mcT1:MovieClip = mcTest; trace(mcTest); frame2(key frame) -> trace(mcT1);

       

      The output is :

      _level0.mcT

                               // There is empty.

       

       

      What i expected of the second output is like bellow:

      _level0.mcT
      _level0.mcT1
      because as variable mcT1 reference to mcTest, the mcTest instance wouldn't be deallocated i thought, who can tell me why ? Thanks a ton !!!

        • 1. Re: A question about object's life time!
          kglad Adobe Community Professional & MVP

          almost none of what you posted is correct.

           

          if mcTest is the instance name of a frame 1 movieclip that does NOT exist on frame 2, then

           

           

          A.

          trace(mcTest);  // in frame 1:->  _level0.mcTest

          trace(mcTest);  // in frame 2:->   undefined

           

          B.

           

          var mcT1:MovieClip=mcTest;  // in frame 1

          trace(mcT1);  // in frame 1:->  _level0.mcTest;

          trace(mcT1);  // in frame 2:->

          1 person found this helpful
          • 2. Re: A question about object's life time!
            xhdreamlover-VT8xt5 Level 1

            yes, you are right, i have made a writing mistake.

             

            But what i want to know is why

             

            B.

             

            var mcT1:MovieClip=mcTest;  // in frame 1

            trace(mcT1);  // in frame 1:->  _level0.mcTest;

            trace(mcT1);  // in frame 2:->  [                       ]   <------------ here is blank ?                               

            • 3. Re: A question about object's life time!
              kglad Adobe Community Professional & MVP

              because mcT1 exists but has no value.  ie, the variable has been declared so, it's not undefined.

               

              however it's value no longer exists so there's nothing to trace.  if you tried to access some property of the movieclip by using

               

              trace(mcT1._name) or trace(mcT1._x) etc, you would then see undefined.  but if you used trace(describeType(mcT1)), you should see "movieclip" because mcT1 has been decleared a movieclip variable.

              • 4. Re: A question about object's life time!
                xhdreamlover-VT8xt5 Level 1

                Why should mcT1 has no value when frame2 entered ? Notice that I had done this "var mcT1:MovieClip = mcTest" on frame1. If you say that mcTest has been deallocated when frame2 entered, then why should flash player deallocated mcTest while it have someone reference to it, mcT1 in this case?

                 

                You know, like bellow:

                 

                var objA: Object = { prop:"abc" };

                var objB: Object = objA;

                 

                trace(objB.prop); // The ouput is "abc".

                 

                delete objA;

                trace(objB.prop); // Here the ouput is still "abc".

                 

                But why when the Object is replaced with TextField, created from the authoring tool instead of the "new" operator, the output result is different ?

                 

                 

                Examples I write above was compiled with action script 2, when compiled with as3, the result was right what i expected, so i guess this "problem" is because the different garbage collection mechanism between different versions of flash player...

                 

                Am i right?

                • 5. Re: A question about object's life time!
                  kglad Adobe Community Professional & MVP

                  that's the way as2 works.

                   

                  when objects are created in the authoring environment they are tied to a frame in a timeline.  if the playhead enters a frame where that object does not exist, the object (and everything dependent on it) are deallocated.

                   

                  when objects are created at runtime (ie, with actionscript), they exist as long as that timeline/movieclip exists.  they are not tied to a frame.  (but, they are tied to the timeline.)