Solved

XML reload

Posted on 2006-11-30
5
2,166 Views
Last Modified: 2012-08-13
I'm looking for a solution to reload XML data every 60 seconds.  

The code below appears to work only when I preview the swf file from Flash.

However, the code doesn't work when the swf is actually published in a browser.  

The code loads an XML file and creates a dynamic menu list.  The problem may be that the dynamic menu list needs to be deleted and refreshed along with the XML, but I'm not sure how to do that.   My amateur solution was to replay the frame containing the actionscript code below every time I wanted to refresh -- but it's apparently not that simple.


ALL THIS CODE ON _ROOT.FRAME50

var item_spacing = 30;
var item_count = 0;
var xspace = 1;

var my_xml = new XML();
my_xml.ignoreWhite = true;
my_xml.onLoad = function(success) {
      if (success) {
            var items = my_xml.firstChild.firstChild.childNodes;
            for (var i = 0; i<items.length; i++) {
                  var item_mc = menu_mc.attachMovie("menu_item 2", "item"+item_count, item_count);
                  item_mc._x = xspace;
                  item_mc._y = item_count*item_spacing;
                  item_mc.location.text = items[i].attributes.type;
                  item_count++;
                  item_mc.main_btn.location_text = items[i].attributes.type;
                  item_mc.main_btn.onRelease = DisplayInfo;
            }
      }
};
my_xml.load("http://www.DOMAIN.com/feedMap/xmlFeed.xml");


var displayTime = 60;

countDown = function(message)
{
_root.timeDisplay.text = "Next update in "+displayTime+" seconds";
displayTime--;
if (displayTime == 0){
clearInterval(timer);
delete my_xml;
gotoAndPlay(50);
}
}
timer = setInterval(countDown, 1000);
0
Comment
Question by:marcparillo
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 13

Accepted Solution

by:
FLAASHER earned 175 total points
ID: 18049473
function flaasher() {
      var my_xml = new XML();
      my_xml.ignoreWhite = true;
      my_xml.onLoad = function(success) {
            if (success) {
                  var items = my_xml.firstChild.firstChild.childNodes;
                  for (var i = 0; i<items.length; i++) {
                        var item_mc = menu_mc.attachMovie("menu_item 2", "item"+item_count, item_count);
                        item_mc._x = xspace;
                        item_mc._y = item_count*item_spacing;
                        item_mc.location.text = items[i].attributes.type;
                        item_count++;
                        item_mc.main_btn.location_text = items[i].attributes.type;
                        item_mc.main_btn.onRelease = DisplayInfo;
                  }
            }
      };
      my_xml.load("http://www.DOMAIN.com/feedMap/xmlFeed.xml");
}


setInterval(_root,"flaasher",1000);//this line will load ur XML file every escond .... if u want eavery 60 esconde multiplay*60 .... so will be setInterval(_root,"flaasher",60000);
0
 
LVL 3

Author Comment

by:marcparillo
ID: 18049977
Thanks FLAASHER!
That makes sense.

I see setInterval will call the function after 60 seconds.
But how do I call the flaasher() function when the swf file loads initially?




0
 
LVL 34

Assisted Solution

by:Aneesh Chopra
Aneesh Chopra earned 175 total points
ID: 18050635
Just call it once manually before calling it using setInterval

for example:

-----------
flaasher();
setInterval(_root,"flaasher",60000);
-----------


- Aneesh
0
 
LVL 3

Author Comment

by:marcparillo
ID: 18053243
Thanks.  That works -- but now I have a new issue:

The dynamic list of buttons that are created within the flaasher() function are not "erased" to reveal the refreshed list of buttons.
I've tried _root.mc_menu.removeMovieClip to clear the stage but that doesn't work.

Is there a command to remove the dynamic menu (menu_mc.attachMovie("menu_item 2", "item"+item_count, item_count) so the new, reloaded XML can create a new list when flaasher() is called every 60 seconds?






0
 
LVL 3

Author Comment

by:marcparillo
ID: 18053669
Ahh -- I figured it out.  It was a variable issue.

One other mention, in case someone else has a similar problem:
The reloading of XML worked in Firefox but not IE because of a caching problem.  I didn't know browsers cached loaded variables differently.

I adjusted the following code to include a random number to trick the swf into not using the cached XML:

var n = random(1000000);
my_xml.load("http://www.nbcnewschannel.com/feedMap/xmlFeed.xml?"+n,"");

Again, thanks for your help!
I'll split up the points.

0

Featured Post

Enroll in May's Course of the Month

May’s Course of the Month is now available! Experts Exchange’s Premium Members and Team Accounts have access to a complimentary course each month as part of their membership—an extra way to increase training and boost professional development.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Flash being Disabled - help! 20 345
File drag and drop 6 158
Script to Delete registry entry based on Product name 6 187
Adobe Products Forum? 3 173
This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
Suggested Courses

710 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question