我的XML停止加载在Flash中
问题描述:
我有一个项目成功地从一个XML文件加载图像来创建一个Flash库。但是,它似乎突然停止了工作。我已经完成了故障排除,发现这是因为SWF不再加载XML文件。不过,我并没有与SWF混淆。我进入FLA文件,代码是相同的。这里是,供参考。我的XML停止加载在Flash中
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>
答
是否有一个crossdomain.xml
文件在您的服务器的根目录(该一个托管你的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文件,否则闪光灯可能不知道它的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>
答
我最终解决了这个问题。我只需调整代码,使其成为一个函数,然后调用函数。这解析了。这里是工作代码
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();
从allowDomain中删除“http:/”。不知道这是否是问题,但它是错误的。并尝试在文件名中只使用小写字母。 – pkyeck
没有这样做,但是谢谢 – Nick
@Nick你应该考虑使用AS3而不是AS2。 – Taurayi