Dynamic Text Field in a Flash Template That Changes with the next command


#1

Hey Guys

I am attempting to build some flash templates that the Text will Change with the Next command.
I will Write in the client:
f0=
Hi
My name
Is

It starts by showing “Hi” the after pushing next it will say “My name is” Etc

I have some old templates that will do this but i dont know how they were made, any new templates i produce wont change on the next command.

Any help would be appreciated


#2

The Next action basically triggers a play()-action in the flash template.
If you put the code stop() on a keyframe in your template, the playhead will stop there. Then when you press Next, the playhead will be continue playing.


#3

yeah it does do that, i was wondering what i would have to do to it to stop it from doing that and making it change the text instead?


#4

If you want to do it from the timeline: Add 3 textfields nemed f0, f1 and f2 (or something else) and make the a motion tween out of every one of them. Let them start at the first frame. Set alpha to 0 for the second and third. after a while set an action frame with a stop(); and after that animate the firsts alpha to 0 and the seconds alpha to one. Repeat this for the third field.

It is also possible to do this from scripting, but involves a bit of programming.


#5

Hi Thanks for the Reply!

That would work, the only problem with that would be the animation out, because each time i use it it might be a different amount of lines so i dont know which layer i should animate out.

Would you know what script i need to add to my .as File?
i assume i would need to use the:

override public function Next():void
{
//Your code here
}
but dont know the script to go in it.


#6

It will be much more versatile and easy to just override the SetData() method because you actually need to break apart that data and change the text on each Next() command with a different line.

Here is an example of a template class (you can follow this guide to make it work) that receives the data from f0 and split that into an array. Each time you call the Next() function it changes the text

Template.as
package
{
	import se.svt.caspar.template.CasparTemplate;
	import flash.utils.setTimeout;
	import flash.text.TextField;
	
	public class Template extends CasparTemplate
	{
		public var lines:Array = new Array();
		public var currentLine:int = 0;
		
		public var _text:TextField; // Text on Stage
		private var someDelay:int = 200; // Delay before updating the TextField
		
		public function Template()
		{
			this.cacheAsBitmap = true;
			this.mouseChildren = false;
			this.mouseEnabled = false;
			
			// Point to the instance on stage
			_text = MovieClipOnStage.TextFieldOnStage;
		}
		
		override public function Next():void
		{
			currentLine++;
			
			if(currentLine == lines.length)
			{
				this.Stop();
			}
			else
			{
				// Some animation to cover or hide the text when it changes
				gotoAndPlay("HideTextAnimation");
				
				// Delay the update
				setTimeout(UpdateText,someDelay);
			}
		}
		
		public function UpdateText()
		{
			_text.text = lines[currentLine];
		}
		
		override public function SetData(xmlData:XML):void 
		{
			super.SetData(xmlData);
			
			var _cname:String;
			var _value:String;
			
			for each (var element:XML in xmlData.children())
			{
				_cname = element.@id;
				_value = element.data.@value;
				
				switch(_cname)
				{
					case "f0":
						// Break apart f0 into an Array
						lines = _value.split("\n");
					
						// And set the first value
						_text.text = lines[0];
						break;
				}
			}
		}
	}
	
}