8 Replies Latest reply on Apr 19, 2006 10:59 AM by Rothrock

    Detect if a level/MC is empty

    davepla
      Hi:

      Is it possible to know if a level/MC is empty before loading a movie into them?

      Thnkas in advance,

      David P.
        • 1. Re: Detect if a level/MC is empty
          Level 7
          davepla wrote:

          > Hi:
          >
          > Is it possible to know if a level/MC is empty before loading a movie into them?

          You could use the "for n in" loop.

          like this:

          function isClipEmpty(clip_mc){
          for (n in clip_mc){
          if (typeof clip_mc[n] eq "movieclip") return false;
          }
          return true;
          }

          Not testet, but should work.

          Btw. is there a better function for typeof, this syntax makes me sick.
          • 2. Re: Detect if a level/MC is empty
            Level 7
            but typeof check if it's a movieclip wich i know. what i need to know if
            it's empty (initial status). i've managed so far testing the mc width:

            if (mc._width == 0)

            what about levels?

            thanks,

            CastTen wrote:
            > davepla wrote:
            >
            >> Hi:
            >>
            >> Is it possible to know if a level/MC is empty before loading a movie
            >> into them?
            >
            >
            > You could use the "for n in" loop.
            >
            > like this:
            >
            > function isClipEmpty(clip_mc){
            > for (n in clip_mc){
            > if (typeof clip_mc[n] eq "movieclip") return false;
            > }
            > return true;
            > }
            >
            > Not testet, but should work.
            >
            > Btw. is there a better function for typeof, this syntax makes me sick.
            • 3. Re: Detect if a level/MC is empty
              Rothrock Level 5
              CastTen you probably should break yourself of using "eq". It has been depreciated for a looong time and they have actually removed it from Flash 8. If you use Flash 8 and publish for earlier versions of the plug-in it should work, but if you publish for 8 it doesn't.

              As for typeof, there is instanceof, but it is IMHO even less useful. It is so odd that there isn't a property with what something is, y'know.

              As for the OP, I'm not quite sure what you mean. Since _levels are created with code, you will know that there are levels because you've put things in them. AFAIK, there is no createEmptyLevel so the only way a level can exist is if you have loaded something into it.

              If you do this trace(_level5) it will return undefined if there is no level 5, but will return _level5 if there is one.

              If by empty you mean has nothing in it you could still use CastTen's solution, but use it something like this:

              for(var a in _level5){

              }
              • 4. Re: Detect if a level/MC is empty
                Level 7
                so, regarding levels, if (_levelN == undefined) should be fine

                Rothrock wrote:
                > CastTen you probably should break yourself of using "eq". It has been
                > depreciated for a looong time and they have actually removed it from Flash 8.
                > If you use Flash 8 and publish for earlier versions of the plug-in it should
                > work, but if you publish for 8 it doesn't.
                >
                > As for typeof, there is instanceof, but it is IMHO even less useful. It is so
                > odd that there isn't a property with what something is, y'know.
                >
                > As for the OP, I'm not quite sure what you mean. Since _levels are created
                > with code, you will know that there are levels because you've put things in
                > them. AFAIK, there is no createEmptyLevel so the only way a level can exist is
                > if you have loaded something into it.
                >
                > If you do this trace(_level5) it will return undefined if there is no level 5,
                > but will return _level5 if there is one.
                >
                > If by empty you mean has nothing in it you could still use CastTen's solution,
                > but use it something like this:
                >
                > for(var a in _level5){
                >
                > }
                >
                • 5. Re: Detect if a level/MC is empty
                  Rothrock Level 5
                  Yeah. If that is what you want. I guess.

                  Since levels aren't something that should happen accidently I'm not really sure how you wouldn't know if it was there or not.

                  I haven't tested what happens if you loadMovieNum and then unloadMovieNum. So I don't know if it goes back to undefined. And I don't know if that is an issue for you.
                  • 6. Re: Detect if a level/MC is empty
                    Level 7
                    Rothrock wrote:

                    > CastTen you probably should break yourself of using "eq". It has been
                    > depreciated for a looong time and they have actually removed it from Flash 8.
                    > If you use Flash 8 and publish for earlier versions of the plug-in it should
                    > work, but if you publish for 8 it doesn't.

                    It does still work in 8. But thanks for your advice.
                    • 7. Re: Detect if a level/MC is empty
                      Level 7
                      John Doe wrote:
                      > but typeof check if it's a movieclip wich i know.

                      My function did check if the clip clip_mc contains any movie clips. You
                      could add any other type to the if-condition of course.

                      > what i need to know if
                      > it's empty (initial status). i've managed so far testing the mc width:
                      >
                      > if (mc._width == 0)
                      >
                      > what about levels?

                      What about getBytesTotal(). Nothing should be smaller than an empty
                      movieclip. What do you mean by empty? Empty like created with
                      createEmptyMovieclip?
                      • 8. Re: Detect if a level/MC is empty
                        Rothrock Level 5
                        Really? Maybe it was "ne" and by extension I just assumed "eq" I do know some of those two letters comparisons have caused folks here problems.

                        Yeah, in the end it all really depends upon what "empty" means. Depending upon what he is trying to accomplish there may be a completely different way of managing the situation. The OP certainly has the ring of that.