Hi,
I try to make simple scorebug. It’s feed from external XML file. I want to start an animation when score changing, but i doesn’t found event listener or dispatcher to get change of value.
My code is:
There is a basic code example for dynamic images here. You can copy your code into the as file and overwrite postInitialize to add the event listener and start the timer.
I have no example as I normally process external data in a custom client and not directly in the template.
It’s kaind of messy from the structure. You should indent properly to get to know, what function starts where and where something else starts. I would do something like that (did not test it):
package
{
import flash.display.MovieClip;
import flash.net.URLLoader;
import flash.events.Event;
import flash.events.TimerEvent;
import flash.net.URLRequest;
import flash.utils.Timer;
import flash.geom.ColorTransform
import se.svt.caspar.ICommunicationManager;
import se.svt.caspar.IRegisteredDataSharer;
import se.svt.caspar.template.CasparTemplate;
public class SCOREBUG_TEST2_AS extends CasparTemplate
{
private var myXMLLoader:URLLoader;
private var myTimer:Timer;
private function timerListener (e:TimerEvent):void
{
myXMLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("D:/Xml.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
}
private function processXML (e:Event):void
{
var myXML:XML = new XML(e.target.data);
TXT.ShotClock.text = myXML.timestamp;
TXT.GameClock.text = myXML.Clock;
TXT.HomeScore.text = myXML.HomeScore;
TXT.AwayScore.text = myXML.AwayScore;
TXT.AwayTeam.text = myXML.AwayName;
TXT.HomeTeam.text = myXML.HomeName;
if (myXML.Period >= 1 && myXML.Period <= 4)
{
TXT.Period.text = (myXML.Period + "/4");
}
else
{
TXT.Period.text ="OT";
}
if ((myXML.timestamp) > 5)
{
var colorYELL:ColorTransform = TXT.ShotClock.transform.colorTransform;
colorYELL.color = 0xFFCC00;
TXT.ShotClock.transform.colorTransform = colorYELL;
}
else
{
var colorRED:ColorTransform = TXT.ShotClock.transform.colorTransform;
colorRED.color = 0xFF0000;
TXT.ShotClock.transform.colorTransform = colorRED;
}
}
override public function postInitialize():void
{
myTimer = new Timer(100);
myTimer.addEventListener(TimerEvent.TIMER, timerListener);
myTimer.start();
}
}
}
I prefere not to have functions local inside other functions, but would do the event handles outside. For that to work you need to declare the variables myXMLLoader and myTimer outside the postInitialize function. I don’t say, that your way of doing it is wrong. But I think mine is a least more readable