Hi,
I’m trying to get a flash template to retrieve data from an external xml file. But I do not make it work.
I think the problem is in the class AS file. Because it works when I put the code on frame one.
Can someone have a look and help me?
AS
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 se.svt.caspar.ICommunicationManager;
import se.svt.caspar.IRegisteredDataSharer;
import se.svt.caspar.template.CasparTemplate;
public class databas_nya extends CasparTemplate
{
private var myXMLLoader:URLLoader;
private var myTimer:Timer;
private function timerListener (e:TimerEvent):void
{
myXMLLoader = new URLLoader();
myXMLLoader.load(new URLRequest("databas.xml"));
myXMLLoader.addEventListener(Event.COMPLETE, processXML);
}
private function processXML (e:Event):void
{
var myXML:XML = new XML(e.target.data);
f0.text=myXML.namn;
f1.text=myXML.title;
}
}
}
There are a few functions that should be overwritten. In the old doc (before GitHub) there was a description of this, but I did not find it any more. At least you should add a postInitialize function:
override public function postInitialize():void {
//code here
}
Inside this you should initialize and start the timer, as this is called by the TemplateHost after the template is loaded and before anything else.
Thank you so much for trying to help me.
I’m not getting the code to work. I have no idea what I’m doing wrong and I’ve tested your idea of postInitialze function.
If you get the time and can check the files I have attached I would appreciate it. But again thanks for all the help.
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 se.svt.caspar.template.CasparTemplate;
public class xmldata extends CasparTemplate
{
var urlLoader:URLLoader = new URLLoader();
var urlRequest:URLRequest = new URLRequest("file:///C:/casparcg/xmldata/databas.xml");
var myTimer:Timer = new Timer(1000);
public function xmldata()
{
urlLoader.addEventListener(Event.COMPLETE, processXML);
myTimer.addEventListener(TimerEvent.TIMER ,timerListener);
myTimer.start();
}
function timerListener(e:TimerEvent):void
{
urlLoader.load(urlRequest);
}
function processXML(e:Event):void
{
var myXML:XML = new XML(e.target.data);
xf0.text = myXML.namn;
xf1.text = myXML.title;
}
}
}