1

I have problem with setting width and height of a movieclip. What i do is create new movieclip add it to stage and then resize and reposition it.

public class mcMainContent extends MovieClip
    {
        var _myStage:Stage;
        public function mcMainContent()
        {

        }
        public function ResizeAndReposition(leftContent:MovieClip,rightContent:MovieClip,myStage:Stage)
        {
            _myStage = myStage;
            x = leftContent.width + 10;

            width = _myStage.stageWidth - leftContent.width - rightContent.width - 10;

            trace("calculated width: " + (_myStage.stageWidth - leftContent.width - rightContent.width - 10) + ", width of element: " + width);

        }
        public function Resize()
        {

        }
        public function Reposition()
        {

        }

    }

I always get width of my movieclip to be 0 even if calculated value is always other number. I tried to call this function before I add movieclip to stage, after I add movieclip to stage but it's width is always 0. Thank you

emirkljucanin
  • 804
  • 1
  • 9
  • 20
  • Just to be sure, this code is in a class which extends MovieClip? What is in this movieclip, how do you add it? Is this class linked to a symbol in an fla library? – Kodiak Nov 16 '11 at 09:44
  • I edited a post with full class code. This movie clip has no children i just want to add it and later add children to it. – emirkljucanin Nov 16 '11 at 09:49

1 Answers1

3

If your MovieClip has no content then its width will always be 0. A MovieClip's width is determined by its content, which scales up and down as you resize the MovieClip. In other words, if your MovieClip contains a shape that is 100px wide, your MovieClip's width will be 100px. If you then set your MovieClip's width to 200px, the inner shape will have a scaleX value of 2.

As a side note, you should be aware that method names should start with a lower case letter. This is to distinguish them from Class names.

shanethehat
  • 15,460
  • 11
  • 57
  • 87