[AS3] Control Template Position by XML value

Is it possible to control template or object position
in Adobe Flash with XML value from external file?

Here what i have done in AS3

  • Create Global var for XML value
  • Do parsing XML file with AS3 function
  • Store the value into variable – I think i miss this part
    (hope it store in global variable, and i can use it in another function)
  • Call the value in function play template
  • The template position is not as I expected
  • Then i ceheck the Variable value on function play template
    The value = NaN,

If it is not the right way, is there another way to do it?

This is my AS3 Code

package 
{
	import flash.utils.*;
	import se.svt.caspar.ICommunicationManager;
	import se.svt.caspar.IRegisteredDataSharer;
	import se.svt.caspar.template.CasparTemplate;
	import fl.containers.UILoader;
	import flash.net.URLRequest;
	import flash.display.MovieClip;
	import flash.events.Event;
	//--------------- GSAP
	import com.greensock.*;
	import com.greensock.easing.*;
	import caurina.transitions.Tweener;
	//untuk reading XML
	import flash.display.*;
	import flash.events.*;
	import flash.net.*;
	import flash.events.Event;
	import flash.net.URLLoader;


	public class next_race extends CasparTemplate
	{
		private const customParameterDescription:XML = 
		<parameters>
		<parameter id="EVENTID" type="string" info="File URL for Flag EventID" />
		<parameter id="SPONSOR1" type="string" info="File URL for Flag Sponsor1" />
		<parameter id="TEMPLATE1" type="string" info="File URL for Flag Bar" />
		</parameters>;;

		override public function SetData(xmlData:XML):void
		{
			super.SetData(xmlData);
			for each (var element:XML in xmlData.children())
			{
				//UILoade

				if (element. @ id == "EVENTID")
				{
					BG.imageevent.source = element.data. @ value.toString();
				}
				if (element. @ id == "SPONSOR1")
				{
					BG.sponsor1.source = element.data. @ value.toString();
				}
				//-------------------------------------------------------
				if (element. @ id == "TEMPLATE1")
				{
					BG.template1.source = element.data. @ value.toString();
				}
			}
		}

		public var PosX:Number; // This is variable name for X Position
		public var Posy:Number; // This is variable name for Y Position

		private var myXML:XML;
		private var XML_URL:String;
		private var myXMLURL:URLRequest;
		private var myLoader:URLLoader;

		public function next_race()
		{
			// init
			myXML = new XML  ;
			XML_URL = "next_race.xml";
			myXMLURL = new URLRequest(XML_URL);
			myLoader = new URLLoader(myXMLURL);
			myLoader.addEventListener(Event.COMPLETE,xmlLoaded);
		}
		// private methods
		private function xmlLoaded(event:Event):void
		{
			myXML = XML(myLoader.data);
			myXML.PositionX;
			PosX = myXML.PositionX; // Pars XML for PosX
			PosY = myXML.PositionY; // Pars XML for PosY
			
			BG.cek1.text = PosX; //check value in dynamic text
		}
		override public function postInitialize():void
		{
			BG.x = PosX // using PosX variable to control position
			BG.y = PosY; // // using PosY variable to control position
		}
		override public function play():void
		{
			TweenMax.to(BG, 1.2, {x:0, y:0, ease:Back.easeOut});
		}
		override public function Stop():void
		{
			BG.cek2.text = PosX; //check value in dynamic text
			TweenMax.to(BG, 1.5, {x:PosX, y:PosY, ease:Back.easeOut}); // using PosX n PosY variable to control position
		}
	}
}

Template File

Comment and help would be appreciate

Best Regard

Gilar
Note: I use Greensock for animation

zPostInitialized is called before the xml file is processed. Move the lines, that set the position into the file load handler.

And check if you don‘t need to extract the values out of the XML in the same way as you do in SetData.

Thanks for the clue didi …