Re: Auto resize text if it doesn't fit text field

#2
Try this:

Code: Select all

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;
	}
}
Arguments:
Input: The text, that shall be displayed in the field
Field: The TextField object
initialFieldWidth: The maximal width of the field.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: Auto resize text if it doesn't fit text field

#3
I put this little customized code on first frame of my text layer:

Code: Select all

private static function ScaleDownTextField(myText.text:String, myText:TextField, 300: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;
   }
}
Than I get this errors:
"Scene 1, Layer 'Layer 1', Frame 1, Line 3 1013: The private attribute may be used only on class property definitions."
"Scene 1, Layer 'Layer 1', Frame 1, Line 3 1012: The static attribute may be used only on definitions inside a class."
"Scene 1, Layer 'Layer 1', Frame 1, Line 3 1084: Syntax error: expecting rightparen before dot."
TV graphics design & animation, Sport CCG Play-out clients
Available for work!

Re: Auto resize text if it doesn't fit text field

#6
The idea of a static function was, that you can use it to scale different textFields in a SetData function. The way you do it is for only one textField, and then you don't need to do a function. By the way, I think you cannot declare a function with fixed arguments. So you modification is probably wrong.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: Auto resize text if it doesn't fit text field

#7
I put this code (now without my modifications)

Code: Select all

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;
   		}
	}
	
	ScaleDownTextField("Hello", myText, 300);
in a separate .as file, and when I run it, I get:
"1120: Access of undefined property TextFieldAutoSize."
"1120: Access of undefined property myText."
TV graphics design & animation, Sport CCG Play-out clients
Available for work!

Re: Auto resize text if it doesn't fit text field

#8
didikunz wrote:You can not put this into a frame, you need to set your textFields from ActionScript in a separate .as file. See this on how to do that: http://casparcg.com/wiki/Content_/_Medi ... _Templates
You need to read the article I pointed you at. It will ONLY work, when you call it from a custom SetData. You can see sort of an example in the tutorial about loadin dynamic images: http://casparcg.com/wiki/Content_/_Medi ... h_Template
Instead of writing the filename on line 22 you would call the function, giving "element.data.@value" as Input value, the textField you want to appear it in as second parameter and the length in the third.

And yes, it willl probably not work with timeline animations. You would need to animate with the Tweener or GreenSocks library or probably you can put your animations into movieclips. The main timeline should only contain a single frame. Sorry, but I have no example template at hand...
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: Auto resize text if it doesn't fit text field

#12
Hi Guys
I've finally got this working so I can auto resize my text and align all left right or centre. Great! Brilliant feature!
One problem... I had been using AS to animate my text in with a fade. To do this I had it in a Movie Clip called Text such as this

Code: Select all

Tweener.addTween(Text, {alpha:1.0, time:0.5, delay:1.3, transition:"linear"});
Now though, I've had to take the text out of the movie clip or the font re scaling function mentioned above doesn't work.
Is there a way to make the font rescaling function work when the text is in a movie clip? I've tried a few things like

Code: Select all

<parameter id="text.f0"....


but I can't figure it.
Any thoughts anyone?
Thanks in advance.

Re: Auto resize text if it doesn't fit text field

#13
If you use my code (further down) then you simply put movieclipName.textfieldName as parameter for Field. It works without modification with any level of nesting, that means, a enclosing moveclip can also be inside a movieclip. The same applies to Tweener also. You can animate any property as long as you reference it in this way.

Code: Select all

Tweener.addTween(OuterMC.InnerMC.Objectname, {alpha:1.0, time:0.5, delay:1.3, transition:"linear"});
Or whatever.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: Auto resize text if it doesn't fit text field

#17
I would split the multiline input (use string.split() ) and put each line into a separate field, that gets scaled down as needed. It would be very complicate to scale inidividual lines in a multiline textfield.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: Auto resize text if it doesn't fit text field

#18
didikunz wrote:I would split the multiline input (use string.split() ) and put each line into a separate field, that gets scaled down as needed. It would be very complicate to scale inidividual lines in a multiline textfield.
I would add that you should calculate the most scaled line percentage and then scale all the lines by that amount so they all look the same size. just applying the function to each separate line independently will make the text appear at different sizes.
Daniel Donoghue
Client and Template Developer

Problems with CasparCG? Guide to posting Bug reports & Feature requests

Re: Auto resize text if it doesn't fit text field

#20
Hi
I use a different approach method that works either on width or height(for multiline texts)

Code: Select all

public function resizeText(mytext: TextField): void {
			if (mytext.height > 79.10) {
				newSize.size--;
				newSize.letterSpacing -= 0.01;
				txtTestFormat.size = newSize.size;
				txtTestFormat.letterSpacing = newSize.letterSpacing;
				mytext.setTextFormat(txtTestFormat);
				mytext.y += 0.7;
				resizeText(mytext);
			}
            
		}
The mytext.y += 0.7 used to centered text at its area

Re: Auto resize text if it doesn't fit text field

#21
didikunz wrote:Try this:

Code: Select all

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;
	}
}
Arguments:
Input: The text, that shall be displayed in the field
Field: The TextField object
initialFieldWidth: The maximal width of the field.
I tried putting this on a .as text and put it on the folder of my .fla.. after compiling with the generator. there's still no text resize when played on the server.

am I missing something?
Attachments
EXP.png
screengrab of the text on my custom software, the files on the folder and the output of the server
EXP.png (88.21 KiB) Viewed 5065 times

Re: Auto resize text if it doesn't fit text field

#22
That is only the part of the story, that scales the field. It has to be embedded in a as file, that overwrites the SetText function. See here:

https://dl.dropboxusercontent.com/u/136 ... ericht.fla
https://dl.dropboxusercontent.com/u/136 ... bericht.as
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Re: Auto resize text if it doesn't fit text field

#23
didikunz wrote:That is only the part of the story, that scales the field. It has to be embedded in a as file, that overwrites the SetText function. See here:

https://dl.dropboxusercontent.com/u/136 ... ericht.fla
https://dl.dropboxusercontent.com/u/136 ... bericht.as
I tried this, and compiled it. All i see is black screen from casparCG server. I'm partly confused. But I'm starting to understand the concept.

Another question is, if using greensock, how do I trigger the animation using the casparCG client?

Thanks

Re: Auto resize text if it doesn't fit text field

#25
This is, where all comes together:
Class_Name.PNG
Class_Name.PNG (39.51 KiB) Viewed 1514 times
When you click on the button were it says "Click here to open ..." you can check the link of the two files, if it goes to the correct .as file, everything is ok. Otherways it will create and open a new file.
Didi Kunz
CasparCG Client-Programmer, Template Maker & Live CG-Operator
Media Support, CH-5722 Gränichen, Switzerland http://mediasupport.ch/
Problems? Guide to posting Bug reports & Feature requests

Who is online

Users browsing this forum: No registered users and 1 guest

cron