Results 1 to 6 of 6
Thread: Auto Reload XML in Flash
-
May 9th, 2012, 09:59 AM #14Registered User
postsAuto Reload XML in Flash
Hi,
I need to reload XML data in Flash as soon as the XML has been updated from back-end.
I have gone through News Ticker Tutorial and It Worked fine.
Here is the link of that tutorial for your reference: http://www.kirupa.com/developer/mx2004/newsticker.htm
I customized the code little bit (am not a flash developer
). In the timer function, I put the xmlData.load... in order to reload the file. Luckily it worked but still didn't fulfil my requirement. When the condition p==total fulfils, it reloads the XML file but fade-in and fadeout the first displayed news very quickly, without any delay and rest of the news works fine. I have spent days to resolve this issue but in vain. Plzzzzzzzzzzzzz help me out. Here is the modification in red colour.
Code:function loadXML(loaded) { if (loaded) { xmlNode = this.firstChild; caption = []; detail = []; from = []; total = xmlNode.childNodes.length; for (i=0; i<total; i++) { caption[i] = xmlNode.childNodes[i].childNodes[0].firstChild.nodeValue; detail[i] = xmlNode.childNodes[i].childNodes[1].firstChild.nodeValue; from[i] = xmlNode.childNodes[i].childNodes[2].firstChild.nodeValue; } first_item(); } else { content = "file not loaded!"; } } xmlData = new XML(); xmlData.ignoreWhite = true; xmlData.onLoad = loadXML; xmlData.load("Z:/news_ho.xml?blarg=" + new Date().getTime()); function first_item() { delay = 3000; p = 0; display(p); p++; } function timer() { myInterval = setInterval(ticker, delay); function ticker() { clearInterval(myInterval); if (p == total) { xmlData.load("Z:/news_ho.xml?blarg=" + new Date().getTime()); p = 0; } fadeout(); } } function display(pos) { over = new TextFormat(); over.underline = true; // out = new TextFormat(); out.underline = false; // TitleMC.newsTitle._alpha = 100; TitleMC.newsTitle.text = caption[pos]; newsMC.newsText._alpha = 100; newsMC.newsText.text = detail[pos]; PostedMC.Postedtxt._alpha = 100; PostedMC.Postedtxt.text = from[pos]; timer(); } function fadeout() { this.onEnterFrame = function() { if (newsMC.newsText._alpha>=0) { newsMC.newsText._alpha -= 5; TitleMC.newsTitle._alpha -= 5; PostedMC.Postedtxt._alpha -= 5; } else { display(p); p++; delete this.onEnterFrame; } }; }
Thanks,
AbdulLast edited by wahababd; May 9th, 2012 at 10:54 AM.
-
May 9th, 2012, 10:54 AM #24Registered User
postsJust now i have updated this thread. (Posted the whole code for better understanding)
-
May 9th, 2012, 11:31 AM #31,391Registered User
postswhen you call load, it also 'restarts' the system by invoking loadXML() then calls first_item() which also calls the timer() method again creating the quick iteration of the first element - you'll need to call a different method or by-pass that call on reloading - the system should be set up to continue as normal - however, you should also 'wait' for the xml to load before proceeding
-
May 10th, 2012, 12:38 AM #44Registered User
postsDear cbeech,
Thanks for your reply. Can you please guide me how to modify the code because am not a developer
. Will really appreciate your help in this regard.
-
May 10th, 2012, 10:45 AM #51,391Registered User
postsok - so really the issue here is that loadXML calls first_item() on success - so we need to control that - see the display doesn't care what data is in the queue, so we should be able to replace that at any time, as long as we don't also invoke a 'restart' of the timing sequence
- so with this code we could simply add a variable to help - BUT we'll also need to change the condition that checks the length of the array, so that on a reload while the system is in operation we don't result with p being out of range - so making these adjustments should do the trick:
under this code, it is difficult to provide a 'hold' until the xml is loaded since methods are 'chained' together - so under this solution, it is likely (more like probably) that it will repeat the 'first' story in the previous load while the new data is loadingCode:var initialized:Boolean = false; function first_item():Void { if( initialized ) return; initialized = true; delay = 3000; p = 0; display(p); p++; } function timer() { myInterval = setInterval(ticker, delay); function ticker() { clearInterval(myInterval); if (p >= total) { xmlData.load("Z:/news_ho.xml?blarg=" + new Date().getTime()); p = 0; } fadeout(); } }Last edited by cbeech; May 10th, 2012 at 10:50 AM.
-
May 11th, 2012, 09:00 AM #64Registered User
postsThank you very much cbeech for all your help and quick response. The code works perfectly fine now

Reply With Quote


Bookmarks