2011-08-08 49 views
0

我有一個項目成功地從一個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> 
+0

從allowDomain中刪除「http:/」。不知道這是否是問題,但它是錯誤的。並嘗試在文件名中只使用小寫字母。 – pkyeck

+0

沒有這樣做,但是謝謝 – Nick

+0

@Nick你應該考慮使用AS3而不是AS2。 – Taurayi

回答

0

是否有一個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> 
+0

我想他是從同一個域加載它 - 所以不需要跨域文件 – pkyeck

+0

我。我只是把它放在那裏,看看它是否會做任何事情,並忘記將其刪除。 – Nick

+0

它沒有提到SWF在哪裏,XML在哪裏,所以我只是猜測。如果有人刪除或更改了crossdomain文件,它可以解釋爲什麼他的SWF停止工作,即使他沒有改變它。 –

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();