4 Replies Latest reply on Sep 29, 2006 6:57 AM by MikeLB

    Item count

      I'm very new to flash and almost embarrassed to ask but is there a simple frame/stage property that returns the number of objects/instances placed on the stage at any one time, I would like to do a loop to a specified count - namely the number of items on the stage/frame.
      Many thanks
        • 1. Re: Item count
          funkysoul Level 4
          if you created the objects via actionscript using a loop, then you can ask how many objects are on the stage, otherwise I'm afraid thats not possible.
          • 2. Re: Item count
            MikeLB Level 1
            Thanks for the reply funkysoul, unfortunately the objects will be placed during authoring so accept that I will have to specify the count. Bit of a shame as we're trying to build a reusable "shell" - we're currently migrating some of our old stuff from director and finding the transition a bit difficult - which leads me to this. Once the objects/instances are placed can you attach a common script/function to them at run time or is that only possible with movie clips are generated on the fly?
            thanks again
            • 3. Re: Item count
              Rothrock Level 5
              You can us a for…in loop to check through all the objects. Of course something like a function or an array is also an object so you will need to check to see if the type of (or is it instanceof?) the object is movieclip.

              Also if there are clips inside clips you will have to decide how to count those.

              Once you have determined you can increment a counter or push the reference to the object into an array and so forth. You can pull it out of the array and dynamically attach predefined event handlers or functions to it.

              I'm away from Flash at the moment so can't test it out and I've never done exactly this so I can't really even make it up off the top of my head. But it should be pretty easy. To get you started, put some things on the stage, add this code on the frame, and work from there.

              for(a in _root){
              trace("Found object: "+_root[a]);
              • 4. Re: Item count
                MikeLB Level 1
                Thanks Rothrock - I'll have to look at it later - code I wanted to attach aint working properly now grrrr! - fun and games eh!