# Dynamic XML Buttons Size and Placement with Masking

**URL:** <https://forum.kirupa.com/t/dynamic-xml-buttons-size-and-placement-with-masking/326269>\
**Category:** flash\
**Created:** [December 3, 2011, 7:17am UTC](https://forum.kirupa.com/t/dynamic-xml-buttons-size-and-placement-with-masking/326269 "2011-12-03T07:17:52Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![amiec](https://avatars.discourse-cdn.com/v4/letter/a/f04885/32.png) [@amiec](https://forum.kirupa.com/u/amiec)\
**Post date:** [December 3, 2011, 7:17am UTC](https://forum.kirupa.com/t/dynamic-xml-buttons-size-and-placement-with-masking/326269/1 "2011-12-03T07:17:52Z")

</div>

So let me try and make this as simple and easy to follow as possible. Pretty much what I am doing is making an XML menu for a website. Each button has a background and and over-state background. The backgrounds are 9 sliced scaled movie clips, well the over-state background is set up to mask an animation movie clip that is larger than any button will be. The mask is 9 slice scaled and is always the same size as the regular background. These backgrounds are x-scaled in a function in the Button.as. The title passed in through the XML determines the width. All of this so far works perfectly.

Now a navigation movie clip processes and adds all of the button movie clips based on the amount of nodes in the XML, this also sets the X and Y coordinates as well as sets a “spacer” between the buttons. Here is my problem, every time the function runs to create a new button, it sets the x value at:

```auto
button.x = this.width;

```

This is great if I don’t use the mask though. What happens since the movie clip I am masking in the over-state background is wider than the buttons are is that there is wayyy to large of a gap. When each button is added, actionscript sees the width of the button with everything in it, masked or not. So I’ve tried a for-loop in the button creating function to increment a number variable from 0 - the max number of buttons in the XML. I then want to set the x value to:

```auto
button.x = (button.background.width * i);

```

This is the background of the button that has the correct width that actionscript should be using. By multiplying it by the i variable, it should move the x right with every button. Unfortunately it’s not working.

Does anyone have any suggestions on how to accomplish this?

- Amie
