As3 script set width and scaleX

Hello.

Is there somehow a way to set the with of a movieclip and have it scaleX = 0?

In my code I do like this in the bottom:

		override public function SetData(xmlData:XML):void 
		{
			super.SetData(xmlData);
			
			for each (var element:XML in xmlData.children())
			{
				if (element.@id == "f0")
				{
					direkte_mc.f0.text = element.data.@value;
				}
				if (element.@id == "f1")
				{
					lokation_mc.f1.text = element.data.@value;
				}
				
			}
			
			direkte_mc.f0.autoSize = TextFieldAutoSize.RIGHT;
			lokation_mc.f1.autoSize = TextFieldAutoSize.RIGHT;
			direkte_vbkg_mc.width = direkte_mc.f0.textWidth + 26.5;
			lokation_vbkg_mc.width = lokation_mc.f1.textWidth + 26.5;

		}

and in the top I do this:

		override public function postInitialize():void
		{
			direkte_vbkg_mc.scaleX = 0;
			lokation_vbkg_mc.scaleX = 0;
		}

But it does not work

I understand, that this code does not work , as you can not set the width like that. What I don‘t understand is, what you try to do. What the effect of this should be.

I have a background that I want to be same length as my text + some xtra.
When I play the template, I want this background to scale from 0 to 100%

Does that make sense?

Now I understand. And lokation_vbkg_mc is the movieClip and the f0 and f1 are textFields, right? You need to set autoSize to LEFT:

direkte_mc.f0.autoSize = TextFieldAutoSize.LEFT;
lokation_mc.f1.autoSize = TextFieldAutoSize.LEFT;

RIGHT does not work (I don’t know why). And you need to set that BEFORE you update the data (before the for each loop) otherwise it will do nothing. Then after the data is set, the width of the textField (not the movieClip) reflects the textlenght. Now you need a way to adjust the length of the background. I usually use a mask, that I move based on the width of the textField, as when you scaleX the whole movieClip the text will get distorted. Then the scaleX of the whole movieclip (including the mask layer etc.) is only used for the animation effect.

It seems to work also with:

direkte_mc.f0.autoSize = TextFieldAutoSize.RIGHT;
lokation_mc.f1.autoSize = TextFieldAutoSize.RIGHT;

But the actual problem is that it doesn’t scaleX from 0 but from the size that it get from:

direkte_vbkg_mc.width = direkte_mc.f0.textWidth + 26.5;
lokation_vbkg_mc.width = lokation_mc.f1.textWidth + 26.5;

to the size of the movieclip.

I need it to scaleX from 0 to that width.

Please read carefully, what I said. And be sure to not mess up the setting of the size for the variable sized background and the animation effect. They have nothing to do with each other. It could also be animating alpha from 0 to 1 or anything else. You first set up the text and background. THEN set the scaleX to 0 to let the animation effect do his job…