我有一个项目,它成功地从XML文件加载图像以制作Flash库。然而,它似乎突然停止了工作。我已经完成了故障排除,发现这是因为SWF不再加载XML文件。但是,我没有搞砸SWF。我进入了FLA文件,代码是一样的。这是它的参考。
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");
};
它确实加载了,但现在将不再有效。我检查过,服务器是Apache,我的情况匹配。我的文件名为“imgDATA.xml”。有没有人经历过这样的事情?
编辑:值得一提的是,我尝试更改目标XML文件的名称和要加载的XML文件,但仍然无法加载。
编辑2:调整SWF代码后,我得到了这个输出
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>
这是我的XML文件:
<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>
答案 0 :(得分:0)
服务器的根目录(承载XML文件的文件)是否有crossdomain.xml
个文件?如果没有,您需要添加它并将其内容设置为:
<?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>
修改强>
尝试设置所有事件处理程序以更好地了解正在发生的事情,然后在此处发布跟踪语句的结果。
myPhoto.onData = function(src:String) { trace("onData:" + src); }
myPhoto.onHTTPStatus = function(httpStatus:Number) { trace("httpStatus:" + httpStatus); }
myPhoto.onLoad = function(success:Boolean) { trace("onLoad:" + success); }
修改强>
尝试向XML文件添加标头,否则Flash可能不知道它的XML数据:
<?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>
答案 1 :(得分:0)
我最终解决了这个问题。我只需要调整代码,使其成为一个函数,然后调用函数。这让它解析了。这是工作代码
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();