You are right, I tested it, and found the same, as you. Sorry for saying something wrong. The code needs to be:
package
{
import flash.display.MovieClip;
import flash.events.IOErrorEvent;
import se.svt.caspar.template.CasparTemplate;
public class UILoader_Test extends CasparTemplate
{
private function loaderIOErrorHandler(errorEvent:IOErrorEvent):void
{
title2.text = " Error ";
}
override public function postInitialize():void
{
Logo.addEventListener(IOErrorEvent.IO_ERROR, loaderIOErrorHandler);
title1.text = " Try to load ";
Logo.source = "file:///D:/-CasparCG Server/templates/DELA.PNG";
}
override public function Play():void
{
}
override public function Stop():void
{
removeTemplate();
}
override public function SetData(xmlData:XML):void
{
//super.SetData(xmlData);
}
}
}
Because the ioError happens asynchronous, we need to catch the event. But you could leave the loaderIOErrorHandler
function empty, to just prevent the template from crashing. By the way: the code, that loads the file into the UILoader
can also be somewhere else (like in the SetData()
function). Because the addEventListener
is called inside postInitialize()
, that is called before anything else, the code would still work.
You find a zip file with my test template here.