开发者

My XML stopped loading in Flash

开发者 https://www.devze.com 2023-03-26 22:37 出处:网络
I had a project which was successfully loading images from an XML file to make a Flash gallery.However, it seems to have suddenly stopped working.I\'ve done troubleshooting and found that it is becaus

I had a project which was successfully loading images from an XML file to make a Flash gallery. However, it seems to have suddenly stopped working. I've done troubleshooting and found that it is because the SWF is no longer loading the XML file. However, I had not messed with the SWF. I went into the FLA file and the code was the same. Here it is, for a reference.

var strTitle = "THIS IS TITLE TEXT";
var strDescription = "This is descriptive";
var intCurrent = 0;
var arrDescription = new Array();//Stores descriptions
var arrTitle = new Array();//Stores titles
var arrMainLoc = new Array();//Stores image locations
var arrThumbLoc = new Array();//Stores thumb locations

var intCurrent:Number = 0;//Used to store the number passed from the button press

stop();
System.security.allowDomain("http:/gretchencomlydesign.com");

myPhoto = new XML();
myPhoto.ignoreWhite = true;
myPhoto.load("imgDATA.xml");
myPhoto.onLoad = function(success)
{
trace("loaded");
var intImageCount = myPhoto.firstChild.childNodes.length;
for (i = 0; i < intImageCount; i++)
{
    arrDescription[i] = myPhoto.firstChild.childNodes[i].attributes.desc;
    arrTitle[i] = myPhoto.firstChild.childNodes[i].attributes.titl;
    arrMainLoc[i] = myPhoto.firstChild.childNodes[i].attributes.main;
    arrThumbLoc[i] = myPhoto.firstChild.childNodes[i].attributes.thumbs;
    //trace(arrTitle[i]);   //Tests Loaded titles
    //trace(arrDescription[i]);    //Tests Loaded descriptions
}
play();
//trace(myPhoto.firstChild.childNodes[0].attributes.desc);
  };
  myPhoto.onLoad = function(false)
  {
    trace("XML failed to load");
  };

It did load, but now will no longer work. I checked and the server is Apache, and my case matches. My file is named "imgDATA.xml". Has anybody ever experienced anything like this?

EDIT: It's worth mentioning that I tried changing the name of the target XML file and the XML file to be loaded, and it still wouldn't load.

Edit 2: After tweaking the SWF code, I ge开发者_StackOverflow社区t this output

loaded
onData:<pop>



<img titl="0" desc="" main="pics/pop/main/0.jpg" thumbs="pics/pop/thumbs/0.jpg"/>

<img titl="1" desc="" main="pics/pop/main/1.jpg" thumbs="pics/pop/thumbs/1.jpg"/>

<img titl="2" desc="" main="pics/pop/main/2.jpg" thumbs="pics/pop/thumbs/2.jpg"/>

<img titl="3" desc="" main="pics/pop/main/3.jpg" thumbs="pics/pop/thumbs/3.jpg"/>





</pop>

Here is my XML file:

<pop>

<img titl="0" desc="" main="pics/pop/main/0.jpg" thumbs="pics/pop/thumbs/0.jpg"/>
<img titl="1" desc="" main="pics/pop/main/1.jpg" thumbs="pics/pop/thumbs/1.jpg"/>
<img titl="2" desc="" main="pics/pop/main/2.jpg" thumbs="pics/pop/thumbs/2.jpg"/>
<img titl="3" desc="" main="pics/pop/main/3.jpg" thumbs="pics/pop/thumbs/3.jpg"/>


</pop>


Is there a crossdomain.xml file at the root of your server (the one that hosts your XML file)? If not, you need to add it and set its content to something like that:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd">
<cross-domain-policy>
   <allow-access-from domain="*" secure="false" />
</cross-domain-policy>

Edit:

Try setting all the event handlers to get a better idea of what's happening, then post the result of the trace statements here.

myPhoto.onData = function(src:String) { trace("onData:" + src); }
myPhoto.onHTTPStatus = function(httpStatus:Number) { trace("httpStatus:" + httpStatus); }
myPhoto.onLoad = function(success:Boolean) { trace("onLoad:" + success); }

Edit:

Try adding a header to your XML file, otherwise Flash might not know it's XML data:

<?xml version="1.0"?>
<pop>
<img titl="0" desc="" main="pics/pop/main/0.jpg" thumbs="pics/pop/thumbs/0.jpg"/>
<img titl="1" desc="" main="pics/pop/main/1.jpg" thumbs="pics/pop/thumbs/1.jpg"/>
<img titl="2" desc="" main="pics/pop/main/2.jpg" thumbs="pics/pop/thumbs/2.jpg"/>
<img titl="3" desc="" main="pics/pop/main/3.jpg" thumbs="pics/pop/thumbs/3.jpg"/>
</pop>


I ended up fixing the problem. I just had to tweak the code so that it made a function, then called the function. That got it parsing. Here is the working code

var strTitle = "THIS IS TITLE TEXT";
var strDescription = "This is descriptive";
var intCurrent = 0;
var arrDescription = new Array();//Stores descriptions
var arrTitle = new Array();//Stores titles
var arrMainLoc = new Array();//Stores image locations
var arrThumbLoc = new Array();//Stores thumb locations

var intCurrent:Number = 0;//Used to store the number passed from the button press

stop();




function processXMLData(success)
{
  if (success)
  {trace("loaded");
    var intImageCount = myPhoto.firstChild.childNodes.length;

    for (i = 0; i < intImageCount; i++)
    {
        arrDescription[i] = myPhoto.firstChild.childNodes[i].attributes.desc;
        arrTitle[i] = myPhoto.firstChild.childNodes[i].attributes.titl;
        arrMainLoc[i] = myPhoto.firstChild.childNodes[i].attributes.main;
        arrThumbLoc[i] = myPhoto.firstChild.childNodes[i].attributes.thumbs;
        trace(arrTitle[i]);//Tests Loaded titles
        trace(arrDescription[i]);//Tests Loaded descriptions

    }
    trace(arrTitle[0]);
    play();
    //trace(myPhoto.firstChild.childNodes[0].attributes.desc);
}    else
  {
    content="Today's news is not found";
  }
  }



var myPhoto=new XML();
myPhoto.ignoreWhite=true;
myPhoto.onLoad=processXMLData;
myPhoto.load("imgDATA.xml");
stop();
0

精彩评论

暂无评论...
验证码 换一张
取 消