place an mc if data in textfield? [*SOLVED*]

#1
Hello en good morning.

I have a problem with an mc I want to place reagarding if there is text in another textfield or not.
I use this, but it does'nt work for me

Code: Select all

public class subs extends CasparTemplate
	{
		override public function postInitialize():void
		{
			top_tekst_mc.alpha = 0;
			top_bkg_mc.alpha = 0;
			bund_tekst_mc.alpha = 0;
			bund_bkg_mc.alpha = 0;
			
			if (bund_tekst_mc.bund_tekst.text == false)
				{
					top_tekst_mc.y = 946;
					top_bkg_mc.y = 982.05;
				}
			if (bund_tekst_mc.bund_tekst.text == true)
				{
					top_tekst_mc.y = 746;
					top_bkg_mc.y = 782.05;
				}
		}
Best regards Tue.
Last edited by tusa on 28 Jun 2017, 10:30, edited 1 time in total.

Re: place an mc if data in textfield?

#2
Sorry, I'm no ActionSript programmer. I use existing code and work with try and error until it Works...Here in office, I can't try anything.

So I only give some ideas, but no solutions.

What happens (or not) and what shall happen ?

My first idea is, that ..... "text.text == true" don't gives the right value. What about ' tekst.text == "" ' ?

My second idea is, that "post initialize", which will run once after init the template, the wrong position for this code, when the field "tekst" will be filled dynamicly ....

I think, this code has to run after an update (sorry, in office i don't have my templates, so I don't know the name of the function)

Re: place an mc if data in textfield?

#3
I second, what thos-berlin said: in postinitialize the textFields are not empty, the code need to go into SetText, after the loop, that fills the data dynamically into the TextFields. And second the if statemaent should read:

Code: Select all

if (bund_tekst_mc.bund_tekst.text != "")
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: place an mc if data in textfield?

#4
You were both right.
I moved it as you wrote didikunz, after setdata

Code: Select all

package
{
	import flash.display.MovieClip;
	import se.svt.caspar.template.CasparTemplate;
	import caurina.transitions.Tweener;
	import flash.display.*;	
	import flash.text.*;
	import flash.text.TextField;
	import flash.text.TextFormat;
	import flash.utils.*;
	
	public class subs extends CasparTemplate
	{
		override public function postInitialize():void
		{
			top_tekst_mc.alpha = 0;
			top_bkg_mc.alpha = 0;
			bund_tekst_mc.alpha = 0;
			bund_bkg_mc.alpha = 0;						
		}
		
		override public function Play():void
		{
			Tweener.addTween(top_tekst_mc, {alpha:1, time:0.04, transition:"linear"});
			Tweener.addTween(top_bkg_mc, {alpha:1, time:0.04, transition:"linear"});
			if (bund_tekst_mc.bund_tekst.textWidth > 0)
			{
				Tweener.addTween(bund_tekst_mc, {alpha:1, time:0.04, transition:"linear"});
				Tweener.addTween(bund_bkg_mc, {alpha:1, time:0.04, transition:"linear"});
			}
		}

		override public function Stop():void
		{
			Tweener.addTween(top_tekst_mc, {alpha:0, time:0.04, transition:"linear"});
			Tweener.addTween(top_bkg_mc, {alpha:0, time:0.04, transition:"linear"});
			if (bund_tekst_mc.bund_tekst.textWidth > 0)
			{
				Tweener.addTween(bund_tekst_mc, {alpha:0, time:0.04, transition:"linear"});
				Tweener.addTween(bund_bkg_mc, {alpha:0, time:0.04, transition:"linear"});
			}
			setTimeout(removeTemplate, 500);
		}
		
		override public function SetData(xmlData:XML):void 
		{
			super.SetData(xmlData);
			
			for each (var element:XML in xmlData.children())
			{
				if (element.@id == "f0")
				{
					top_tekst_mc.top_tekst.text = element.data.@value;
				}
				if (element.@id == "f1")
				{
					bund_tekst_mc.bund_tekst.text = element.data.@value;
				}
			}
			
			if (bund_tekst_mc.bund_tekst.textWidth == 0)
			{
				top_tekst_mc.y = 946;
				top_bkg_mc.y = 982.05;
			}
			
			top_tekst_mc.top_tekst.autoSize = TextFieldAutoSize.CENTER;
			bund_tekst_mc.bund_tekst.autoSize = TextFieldAutoSize.CENTER;
			top_bkg_mc.width = top_tekst_mc.top_tekst.textWidth + 20;
			bund_bkg_mc.width = bund_tekst_mc.bund_tekst.textWidth + 20;
		}
	}
}