Update command, wrong behavior with flash template

Hi there! Can you tell me why after an update, the code is executed incorrectly?

The code is that the two texts above modify the width according to the size of the text. But after an update, the text changes alignment and behaves differently from the code. Would someone explain to me why?

Correct template:

After updating:

Code:

package
{
	import flash.display.MovieClip;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextField;
	import flash.text.TextFormat;	
	import flash.utils.Timer;
    import flash.events.TimerEvent;
    import flash.events.Event;
	import flash.display.Shape; 
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import se.svt.caspar.ICommunicationManager;
	import se.svt.caspar.IRegisteredDataSharer;
	import se.svt.caspar.template.CasparTemplate;
		
	public class Textos extends CasparTemplate
	{
		
		private const customParameterDescription:XML = 	
		<parameters>
	   		<parameter id="f0" type="string" info="Texto o url de txt" />
			<parameter id="f1" type="string" info="Texto o url de txt" />
			<parameter id="f2" type="string" info="Texto o url de txt" />
	   		</parameters>;
		
		private var init:Boolean = false;
					
		override public function SetData(xmlData:XML):void 
		{			
		   for each (var element:XML in xmlData.children())
		   {
			if (element.@id == "f0") 		
			  {
				var f0 = element.data.@value.toString();
						
				var f0A:String = f0.substr(-4);
				var Input:String;
				  
				if (f0A == ".txt")
					{
						var url:String = "E:/Server/templates/A diario/" + f0;
						var loader:URLLoader = new URLLoader(new URLRequest(url));
						loader.addEventListener(Event.COMPLETE, onFileLoaded);
						function onFileLoaded(e:Event):void
							{
									var loader:URLLoader = e.target as URLLoader;
									var text:String = loader.data; // variable text now holds the text from the file
									a0.a0.text = text;
			
									var format:TextFormat = new TextFormat();
			
									function updateFormat(size:int):void
										{
										format.size = size;
										a0.a0.setTextFormat( format );
										}
			
									var smallLimit:int = 5;
									var testSize  = a0.a0.getTextFormat().size;
									while ( testSize > smallLimit )
										{
										updateFormat( testSize );
										trace( a0.a0.numLines  );

										if (a0.a0.numLines > 2)
											{
											testSize--;
											}
											else
												{
												testSize = smallLimit;
												}
										}
							}
					}		
				else if (f0A != ".txt")
					{
					a0.a0.text = f0;
			
									var format:TextFormat = new TextFormat();
			
									function updateFormat(size:int):void
										{
										format.size = size;
										a0.a0.setTextFormat( format );
										}
			
									var smallLimit:int = 5;
									var testSize  = a0.a0.getTextFormat().size;
									while ( testSize > smallLimit )
										{
										updateFormat( testSize );
										trace( a0.a0.numLines  );

										if (a0.a0.numLines > 2)
											{
											testSize--;
											}
											else
												{
												testSize = smallLimit;
												}
										}
					}
								
				}

			if (element.@id == "f1") 		
			  {
				var f1 = element.data.@value.toString();
						
				var f1A:String = f1.substr(-4);
				  
				if (f1A == ".txt")
					{
						var url1:String = "E:/Server/templates/A diario/" + f1;
						var loader1:URLLoader = new URLLoader(new URLRequest(url1));
						loader1.addEventListener(Event.COMPLETE, onFileLoaded1);
						function onFileLoaded1(e1:Event):void
							{
									var loader1:URLLoader = e1.target as URLLoader;
									var text1:String = loader1.data; // variable text now holds the text from the file
									var wi1:int = a1.a1.width;
									a1.a1.autoSize = TextFieldAutoSize.CENTER;
									a1.a1.text = text1
									if (wi1 < a1.a1.width)
										{
											a1.a1.scaleX = wi1 / a1.a1.width;
											a1.a1.x = 0;
										}
							}
					}		
				else if (f1A != ".txt")
					{
					var wi11:int = a1.a1.width;
					a1.a1.autoSize = TextFieldAutoSize.CENTER;
					a1.a1.text = f1
					if (wi11 < a1.a1.width)
						{
						a1.a1.scaleX = wi11 / a1.a1.width;
						a1.a1.x = 0;
						}
					}
								
				}
			   
			if (element.@id == "f2") 		
			  {
				var f2 = element.data.@value.toString();
						
				var f2A:String = f2.substr(-4);
				  
				if (f2A == ".txt")
					{
						var url2:String = "E:/Server/templates/A diario/" + f2;
						var loader2:URLLoader = new URLLoader(new URLRequest(url2));
						loader2.addEventListener(Event.COMPLETE, onFileLoaded2);
						function onFileLoaded2(e2:Event):void
							{
									var loader2:URLLoader = e2.target as URLLoader;
									var text2:String = loader2.data; // variable text now holds the text from the file
									var wi2:int = a2.a2.width;
									a2.a2.autoSize = TextFieldAutoSize.CENTER;
									a2.a2.text = text2
									if (wi2 < a2.a2.width)
										{
											a2.a2.scaleX = wi2 / a2.a2.width;
											a2.a2.x = 0;
										}
							}
					}		
				else if (f2A != ".txt")
					{
					var wi22:int = a2.a2.width;
					a2.a2.autoSize = TextFieldAutoSize.CENTER;
					a2.a2.text = f2
					if (wi22 < a2.a2.width)
						{
						a2.a2.scaleX = wi22 / a2.a2.width;
						a2.a2.x = 0;
						}
					}
								
				}

			}	
		}
	}
}

I also ask if they have any idea how to perform an update using tweener in the same way as I use for the input and output of the template but only for texts.

I don’t think, that debugging your code is the way it should go in this forum. This code is too long and too messy to see any issues easily. So I guess no body will be willing to do your work.

Just one idea for free :slight_smile: : Be aware, that a field, that has been changed in size by manipulating it’s scaleX property is keeping this scaling if your code does not reset it before setting new text.

One point and I’m wondering why dont you have problems when debug
a1.a1.text = f1 need and ; at the end
next is you use the same name for movieclip and for text ex a1 is a movieclip and also a text inside a movieclip with the same name strange
I would do someting like mc_a1 for movieclip and a1_txt for text

		public function ShowActive(): void{
			ScaleDownTextField(Liststr,mcactive.activelist,1520,-761.5,1);
			TweenLite.to(mcactive, 10, {useFrames: true,alpha: 1});
		}
		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;
			}
		}

Also this Scale works for me If I remember well is Didi’s code

Excuse me, if I should send only the part of the code I was interested in. But it worked yes, I didn’t consider the issue of scale. I am not a programmer, I just try to solve my needs by studying. Thank you so much to both of you.