4 Replies Latest reply on May 27, 2006 8:48 PM by >Vee<

    Reading the width of a movieclip

    >Vee< Level 1
      I am creating my clips from library using attach.... The instance names and counts are all stored in arrays. All of this works fine when I trace it. the next step on my journey was to try to read the width of the first placed clip and make each succesive clip move 100 or so pixels to the right. Heres what I have been trying:

        • 1. Re: Reading the width of a movieclip
          2m Level 2

          what your doing is overly comlicated but most of it isnt wrong.

          you would have to change the last line to:
          _root[top_menu_instance_arr[v]]._x = widthHolder +100;

          but first of al im not sure if that is what you really wnt, if you want to sort then side by side, one afer another you havet to sum up the widthes (pls spaces between them) and position the clips accordingly.

          To simplyfiy it:

          You dont need to have that function getMCWidth, as tha width is a publicly accesable property of every movieclip, you can just write MC._width instead.

          and the goot thing wit attachMovie is that it returns a reference to the newly attached clip, so if you store that in a (temporary) variable you dont have to acces the clip throug _root[....

          I'd suggest this:

          // Start at 0, but you can change that at will
          var widthHolder:Number = 0;
          for (var v:Number = 0; v<topButtonCount; v++) {
          // the instance names trace perfectly
          va tmp_mc = this.attachMovie("main_menu", top_menu_instance_arr[v], this.getNextHighestDepth(), {_y:100}); // only send y as we're goint to change x anyhow
          tmp_mc._x = widthHolder
          // Add the width of our clip to widthHolder plus 100 px for spacing
          // wach out for the "+=", we add to the value without reseting it!
          widthHolder += tmp_mc._width + 100;
          • 2. Reading the width of a movieclip
            >Vee< Level 1
            thanks for your response. it worked great. I never ever (and im sure im lacking b/c of this) used the operand "+=", so im trying to get used to it. As i see it it just looks like a shortcut in a way. if i read that statement I could say "keep my existing _x and add this to it", is that right? Below is something similar I was playing around with for sub menus.
            for (var i = 0; i<10; i++) {
            var my_mc = attachMovie("sub_mc", "sub_mc"+i, this.getNextHighestDepth(), {_x:0, _y:0});
            my_mc._y += this._height;

            Why doesnt the attached mc start from 0,0? I can't understand it. I thought it would naturally default to those coordinates. The _x = 0 but the _y is rather far down on the stage.

            thanks again
            • 3. Re: Reading the width of a movieclip
              Juankpro Level 2
              When placing objects with action script the objects are aligned using its transformation point. So create your movie clips with the transformation point on the top left corner of its graphic contents.
              • 4. Re: Reading the width of a movieclip
                >Vee< Level 1
                it already was at that point - I checked, any other ideas?