emirkljucanin
emirkljucanin

Reputation: 814

width of element not set properly with actionscript

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

Upvotes: 1

Views: 574

Answers (1)

shanethehat
shanethehat

Reputation: 15560

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.

Upvotes: 3

Related Questions