Bonjour à tous.
Je désire pouvoir avoir accès au contenu de ma variable "contenuXMLFichier" en dehors de la fonction onLoad et j avais trouvé un code sensé résoudre mon problème. Hélas ca ne marche pas, voici mon code:
import mx.utils.Delegate;
class XMLContentLoader
{
public var contenuXMLFichier:Array = new Array();
public var nbPhotos:Number;
private var xml:XML;
function XMLContentLoader(url:String)
{
xml = new XML();
xml.ignoreWhite = true;
xml.onLoad = Delegate.create(this, onLoadEvent);
xml.load(url);
}
function onLoadEvent(success:Boolean):Void
{
if(success)
{
nbPhotos = xml.firstChild.childNodes.length;//récupérer le nombre de photos
for(var i:Number=0; i<nbPhotos; i++)
{
contenuXMLFichier[i]=xml.firstChild.childNodes[i].attributes.fichier;
}
}
trace(contenuXMLFichier[0]); //Affiche correctement le nom de mon 1er fichier
}
}
Et Dans mon .fla :
System.useCodepage = true;
import XMLContentLoader.*;
var espace:Number = 10;
var photoX:Number = espace;
var photoY:Number = espace;
var xmlCL:XMLContentLoader = new XMLContentLoader("../xml/sanguines.xml");
trace(xmlCL.contenuXMLFichier[0]); //Affiche undefined
Voila, l'utilisation de "Delegate" était sensé résoudre mon problème mais ca ne marche toujours pas, quelqu'un aurait-il une solution ?
Merci.
Renaud