Мой XML перестал загружаться во Flash - PullRequest
0 голосов
/ 08 августа 2011

У меня был проект, который успешно загружал изображения из файла 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>

Ответы [ 2 ]

0 голосов
/ 08 августа 2011

Я решил проблему. Мне просто пришлось настроить код, чтобы он сделал функцию, а затем вызвал функцию. Это получилось при разборе. Вот рабочий код

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 голосов
/ 08 августа 2011

Есть ли файл 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, в противном случае 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>
...