Hey guys!
It´s been awhile, so lets not waste anymore time!
The problem I´m having is that I can´t update the information that I get from my XML file at runtime.
I have some static textfields that updates just fine, but it´s the dynamic ones that don´t play nice.
The project is a small display that shows the amount of minutes that is left from the time set in the XML to the current time. I don´t want to bore you too much with the details of it all.
Here´s the code! Right now though it doesn´t update at all. Removed those bits of code since it got me nowhere, just hoping someone has done this before and knows the trick
var container:Sprite = new Sprite();
bottom_mc.addChild(container);
var loader:URLLoader = new URLLoader();
var blocks:XMLList = null;
loader.addEventListener(Event.COMPLETE,loadXML);
loader.load(new URLRequest("data/subway.xml"));
function loadXML(e:Event):void
{
var fileTxt:String = e.target.data as String;
blocks = new XML(fileTxt).children();
for (var i:int=1; i<blocks.length(); i++)
{
var xmlblock:XML = blocks*;
var block:XMLList = xmlblock.children();
var _content:String = block[0].text();
var _month2:Number = 7;
var _day2:Number = block[1].text();
var _hour2:Number = block[2].text();
var _min2:Number = block[3].text();
var endDate2:Date = new Date(2011,_day2,_hour2,_hour2,_min2);
addText(_content,endDate2,(i==1?true:false));
}
animate();
}
//sets the bottom textfield
function addText(_content:String,endDate2:Date,firstBlock:Boolean=false):void
{
var content_text:TextField = new TextField();
content_text.htmlText = _content;
content_text.setTextFormat(txtFormat);
content_text.x = container.width + (firstBlock?0:100);
container.addChild(content_text);
var now:Date = new Date();
var timeLeft:Number = endDate2.getTime() - now.getTime();
var seconds:Number = Math.floor(timeLeft / 1000);
var minutes:Number = Math.floor(seconds / 60);
var hours:Number = Math.floor(minutes / 60);
var days:Number = Math.floor(hours / 24);
seconds %= 60;
minutes %= 60;
hours %= 24;
var min:String = minutes.toString();
var time:String = min;
var time_text:TextField = new TextField();
time_text.text = time;
time_text.x = container.width + 10;
container.addChild(time_text);
var _min:TextField = new TextField();
_min.text = " min";
_min.x = container.width - 10;
container.addChild(_min);
}
//animates the bottom_mc ;
function animate():void
{
var _num:Number = Math.floor((bottom_mc.width as Number) / 100);
var _xValue:Number = Math.floor(bottom_mc.width - (bottom_mc.width * 2));
if (bottom_mc.x == Math.floor(bottom_mc.width - (bottom_mc.width * 2)))
{
bottom_mc.x = 700;
TweenLite.to(bottom_mc, _num, {x:_xValue, ease:None.easeNone, onComplete:animate});
}
else
{
TweenLite.to(bottom_mc, _num, {x:_xValue, ease:None.easeNone, onComplete:animate});
}
}
Now, for the update part, I was planning on doing it inside the last function, animate().
Since that´s when the MC is outside of the stage, and I can repopulate it with new information without showing it to the viewer.
Too much yadda yadda from my part, I´ll leave it at that with hopes that it´s sufficient enough for someone to give me some helpful pointers.
Like always, thanks alot in advance!
/rundevo