Text problem while using masked animations and autosize script


#1

Hello, I’m trying to create a text with a mask animation, it works, but when I try to use a AutoSize Script the text disappears.

Any type of help is welcome! :slight_smile:

Files: https://drive.google.com/open?id=1B1-2uEhc2nPyPzYXJ8qVaTq_IMWqHtSp


#2

Try with this code:

		private static function ScaleDownTextField(Input:String, Field:TextField, initialFieldWidth:int, initialFieldX:int, align:int):void
		{
			var wi:int = initialFieldWidth;
		    Field.autoSize = TextFieldAutoSize.LEFT;
			Field.scaleX = 1;
		    Field.text = Input;
			if (wi < Field.width)
			{
		    	Field.scaleX = wi / Field.width;
			}
		
			if (align == 0)  //left
			{
				Field.x = initialFieldX;
			}
			if (align == 1)  //center
			{
				Field.x = initialFieldX + (initialFieldWidth - Field.width) / 2;
			}
			if (align == 2)  //right
			{
				Field.x = initialFieldX + initialFieldWidth - Field.width;
			}
		}

Arguments:

  • Input: the text (element.data.@value).
  • Field: The instance name of the textfield
  • initialFieldWidth: Maximal width the field should have
  • initialFieldX: The x-coordinate of the field
  • align: 0=Left, 1=Center, 2=Right

#3

Hi didikunz!
Your code is working for me, but when my mask reach the last frame of the animation the text changes to the text I’ve written on Adobe Flash.

Prints: https://imgur.com/a/XjawTXA

Files: https://drive.google.com/open?id=1Mb_RUn7VYylJYdbaR27GUwajsBGserG7

Thanks!


#4

Make sure, that the tween of the text is in one piece, use a motion tween.


#5

Worked using a motion tween on the text’s mask!

Thanks for the help didikunz!


#6

I have tried the script and it’s work
I wan to ask something …
Is it possible to un-overide text position
because i want to do it manual.

I try to modify the code but not success

private static function ScaleDownTextField(Input:String, Field:TextField, initialFieldWidth:int):void
{
var wi:int = initialFieldWidth;
Field.autoSize = TextFieldAutoSize.LEFT;
Field.scaleX = 1;
Field.text = Input;
if (wi < Field.width)
{
Field.scaleX = wi / Field.width;
}
}

  public override function SetData(xmlData:XML):void{						
  	for each (var element:XML in xmlData.children()){
  		if (element.@id == "teste"){
  			ScaleDownTextField(element.data.@value, teks.teste, 881);
  		}
  		if (element.@id == "even"){
  			ScaleDownTextField(element.data.@value, teks2.even, 877);
  		}

Thanks


#7

I don‘t understand that. What do you want?


#8

Ohh Sorry …
It mean, I wanto manage text position and align manual by maouse in Adobe Flash
not by script script in AS3. and only text width will controlled by AS3

So i try to remove this.

private static function ScaleDownTextField(Input:String, Field:TextField, initialFieldWidth:int, initialFieldX:int, align:int):void

if (align == 0) //left
{
Field.x = initialFieldX;
}
if (align == 1) //center
{
Field.x = initialFieldX + (initialFieldWidth - Field.width) / 2;
}
if (align == 2) //right
{
Field.x = initialFieldX + initialFieldWidth - Field.width;
}

and

ScaleDownTextField(element.data.@value, teks.team2, 498**, 645, 3**); // lebar max, position in symbol,

align


#9

You can get rid of all that code, when you want to manage everything by yourself. If you want to have the scaling functionality you need to keep the code. The problem is, that to be able to scale the text, the textfields alignment property get lost, because the autoSize property actually only work as expected when set to TextFieldAutoSize.LEFT.

The code you use is an old version of that function, that only can handle left aligned text. Today I normally use the code bellow:

		private static function ScaleDownTextField(Input:String, Field:TextField, initialFieldWidth:int, initialFieldX:int, align:int):void
		{
			var wi:int = initialFieldWidth;
		    Field.autoSize = TextFieldAutoSize.LEFT;
			Field.scaleX = 1;
		    Field.text = Input;
			if (wi < Field.width)
			{
		    	Field.scaleX = wi / Field.width;
			}
			
			if (align == 1)  //center
			{
				Field.x = initialFieldX + (initialFieldWidth - Field.width) / 2;
			}
			if (align == 2)  //right
			{
				Field.x = initialFieldX + initialFieldWidth - Field.width;
			}
		}

It has the align parameter. Set it to 0 for left align, to 1 for center align and to 2 for right align. The initialFieldWidth parameter defines the maximum width the field can grow (it is, what it is initially set to in the designer) and the initialFieldX is the X-coordinate the field has been set in the designer. These two parameters are necessary to scale the field and keep it at it’s place.


#10

Thanks Didi