6 Replies Latest reply on Apr 22, 2006 3:45 PM by Newsgroup_User

    variable = library item's properties

    maguskrool Level 1
      Hi.

      I have several Movie Clips on my project's library and I need to retrieve their properties in order to assign them to certain variables. at a given point I will attach those MCs to the stage, but I needed their widths, heights, etc. before, in order to calculate the positions where I'll attach them and other MCs. So what I need to know is if there is a way to retrieve those properties directly from the library, perhaps using linkage ids or something of the kind, without needing to have the MCs attached. Thank you in advance.
        • 1. Re: variable = library item's properties
          Peter Lorent Level 2
          Nope. But you can use an object that holds the props of the mc's.
          • 2. Re: variable = library item's properties
            Level 7
            maguskrool,

            >> I have several Movie Clips on my project's library and
            >> I need to retrieve their properties in order to assign
            >> them to certain variables. at a given point I will attach
            >> those MCs to the stage, but I needed their widths,
            >> heights, etc. before, in order to calculate the positions
            >> where I'll attach them and other MCs.

            You're making an incorrect assumption, here; namely, that you must know
            this information *before* you attach your movie clips. In fact, when you
            attach your Library items, you may immediately follow the attachment with
            adjustments to any of the clip's properties. The visual display will not be
            updated until all the ActionScript in that frame has been executed.


            David
            stiller (at) quip (dot) net
            Dev essays: http://www.quip.net/blog/
            "Luck is the residue of good design."


            • 3. Re: variable = library item's properties
              maguskrool Level 1
              Thank you, but that's what I needed the properties for in the first place, to build those objects. Guess I'm stuck with a couple tricks I figured out to make this work, though they're not an ideal solution. Thanks for the quick reply
              • 4. Re: variable = library item's properties
                Level 7
                maguskrool,

                > Thank you, but that's what I needed the properties
                > for in the first place, to build those objects.

                I really can't imagine why you believe you have a problem. If you want
                to construct, for example, a movie clip object in real time, you have quite
                a few options. You may use MovieClip.createEmptyMovieClip() or
                MovieClip.attachMovie() to either create or attach movies directly to the
                Stage or to the timelines of existing clips. Before any visuals update, you
                have the time to adjust the created/attached movie clips in any way you
                please: resize them, reposition them, and so on, as dictated by the
                MovieClip class.

                > Guess I'm stuck with a couple tricks I figured out
                > to make this work, though they're not an ideal
                > solution.

                What tricks are you talking about? Why do you assert they aren't ideal?


                David
                stiller (at) quip (dot) net
                Dev essays: http://www.quip.net/blog/
                "Luck is the residue of good design."


                • 5. Re: variable = library item's properties
                  maguskrool Level 1
                  I didn't explain my whole project because it wasn't necessary to my essential question, but here is why I need those properties to begin with.

                  This is sort of a game and the objective is to fill the Stage with as many MCs as possible. You begin with a random MC and when you place it a new random one appears and so forth. You can't place MCs over others already placed.

                  The Stage is empty, the Library is full of MCs of various dimensions. This is a group project, so I'm not responsible for the MCs, only for the general structure of the thing. The MCs will snap only at certain coordinates when they are placed by the user. Those coordinates will depend on the widths and heights of the other MCs in the library. Valid X coordinates must be equal to a*MC1._width+b*MC2._width+,...,+z*MCn._width. So, if width1 = 13, width2 = 3 and width3 = 7.25, then 70 would be a valid X coordinate (2*13 + 5*3 + 4*7.25 = 70). Same for the Y coordinates.

                  There are multiple environments and each time this game loads you'll have a group of random pieces to place, from a total of dozens. Also, there will be pieces removed, changed or added at later times, perhaps monthly or so. So, ok, I could build arrays with the widths and heights of all the different MCs, but not only would that be tiresome and error prone (and harder to debug), but it would require changing those arrays at every update. So if I could have all the properties I need before, it would be so much simpler. Every time the game loads it decides the random six or seven pieces it's going to use, and then calculates the valid coordinates based on those pieces' properties.

                  The trick I used was to have the game attach all the pieces at the beginning with _alpha = 0, then build the width and height arrays and then remove all MCs again before the game actually began. Perhaps there is a simpler way? Thank you.
                  • 6. Re: variable = library item's properties
                    Level 7
                    maguskrool,

                    > This is sort of a game and the objective is to fill the Stage
                    > with as many MCs as possible. You begin with a random
                    > MC and when you place it a new random one appears
                    > and so forth. You can't place MCs over others already
                    > placed.
                    // more, snipped

                    Your description is thorough, which isn't common enough in questions
                    posted here. I applaud that. The "trick" you mention -- of attaching
                    clips invisibly, then gathering data -- is a good one.

                    The fact remains, for better or worse, that your data are not accessible
                    until the movie clips have been attached. They simply aren't available to
                    ActionScript until present on the Stage.

                    You mention "all those arrays," but I only see that one array is
                    necessary. In fact, you don't actually *need* arrays at all, since you
                    could create a single "container" clip at the very beginning, set its
                    MovieClip._visible property to false, then attach the other clips as sub
                    clips of that. Once gathered there, you could loop through the container
                    clip's properties using the typeof operator to determine which ones are
                    movie clips, then access widths and heights as needed. Personally, I
                    *would* use an array, but just one. Create that container clip and set its
                    _visible to false, then as you attach each Library clip, push that clip's
                    instance name into the array. In one swoop, you have access to each clip's
                    width and height.

                    var hiddenClips:Array = new Array();
                    container._visible = false;
                    hiddenClips.push(
                    container.attachMovie(
                    "libClipA",
                    "mcClipA",
                    container.getNextHighestDepth()
                    )
                    );
                    hiddenClips.push(
                    container.attachMovie(
                    "libClipB",
                    "mcClipB",
                    container.getNextHighestDepth()
                    )
                    );
                    // etc.

                    Then later ...

                    hiddenClips[0]._width
                    hiddenClips[1]._height
                    // etc.


                    David
                    stiller (at) quip (dot) net
                    Dev essays: http://www.quip.net/blog/
                    "Luck is the residue of good design."