Salve, stavo facendo delle prove con Flash. In particolare stavo tentando di leggere alcune informazioni da un file XML.
Ho un file XML strutturato in questa maniera:
Codice PHP:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<zona xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<tipoalloggio>
<comune>Abc</comune>
<nome>Nido dei merli</nome>
<indirizzo>Via Maritano, 1</indirizzo>
<tel>555 5555555</tel>
<fax>444 4444444</fax>
<email>info@nidodeimerli.it</email>
<web>[url]www.nid.it[/url]</web>
<camere>6</camere>
<servizi>parcheggio</servizi>
</tipoalloggio>
.....
</zona>
Ho creato un piccolo action script collegato ad un piccolo form (che per ora non serve a nulla):
Codice PHP:
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
contact_name.text = contact_email.text = "";
send_button.addEventListener(MouseEvent.CLICK, submit);
reset_button.addEventListener(MouseEvent.CLICK, reset);
var timer:Timer;
var var_load:URLLoader = new URLLoader;
function submit(e:MouseEvent):void
{
if( contact_name.text == "" || contact_email.text == "")
{
message_status.text = "Please fill up all text fields.";
}
else
{
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
xmlLoader.load(new URLRequest("affittacamere_penisolasorrentina_capri.xml"));
}
}
function reset(e:MouseEvent):void
{
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = "";
}
function receive_response(e:Event):void
{
var loader:URLLoader = URLLoader(e.target);
var email_status = new URLVariables(loader.data).success;
if( email_status == "yes" )
{
message_status.text = "Success! Your message was sent.";
timer = new Timer(500);
timer.addEventListener(TimerEvent.TIMER, on_timer);
timer.start();
}
else
{
message_status.text = "Failed! Your message cannot sent.";
}
}
function on_timer(te:TimerEvent):void
{
if( timer.currentCount >= 10 )
{
contact_name.text = contact_email.text = contact_subject.text =
contact_message.text = message_status.text = "";
timer.removeEventListener(TimerEvent.TIMER, on_timer);
}
}
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParseStructure(xmlData);
}
function ParseStructure(structureInput:XML):void {
trace("XML Output");
trace("------------------------");
var structureList:XMLList = structureInput.tipoalloggio.(comune == "abc");
trace(structureList);
}
l'errore in output è il seguente:
Codice PHP:
XML Output ------------------------
ReferenceError: Error #1065: La variabile comune non è definita.
at prova2_fla::contactform_1/ParseStructure() at prova2_fla::contactform_1/LoadXML()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/flash.net:URLLoader::onComplete()
dov'è l'erreore???
se provo a scrivere:
var structureList:XMLList = structureInput.tipoalloggio.comune;
mi mostra solo tutti i comuni presenti all'interno del file XML. Ho trovato sulla rete l'esempio che vedete nel listato per dare in output solo i comuni in cui c'è scritto "abc". Ma non va! L'errore lo da una volta premuto il tasto send. Come devo fare???
Un'altra cosa che non riesco a fare è mettere al posto di "abc" il valore ottenuto dal form, mi date qualche dritta??
Grazie!