Flash 8 Bug: XML.idMap
Par Stéphane Bebrone le samedi, août 5 2006, 17:25 - Flash - Lien permanent
Pour l'anecdote, je répondais à un poste sur le forum Flash de Media-box sur la manière façon de procéder pour atteindre un noeud particulier d'un fichier XML depuis son attribut id.
C'était l'occasion de tester la propriété idMap de l'objet XML apparue sous Flash 8 (remplaçant la fonction caché de Flash MX 2K4). Je tenta donc de compiler cet exemple tout simple:
actionscriptvar xml:XML = new XML(); xml.ignoreWhite = true; xml.onLoad = function() { trace(xml.idMap["2"].attributes.nom); } xml.load("data.xml");
Qui me donna pourtant un message d'erreur:
There is no property with the name 'idMap'.
Chose étrange, puisque l'exemple de la documentation fonctionne parfaitement. Sauf qu'à y regarder du plus près, les développeurs ont pris soin de ne pas typer fort leur objet XML.
Je ne vois que deux workarounds au problème:
- Ne pas typer son objet XML. Ca fonctionnera mais bon c'est quand même un peu dommage de devoir se passer du typage fort.
- Editer le fichier intrinsic de la classe XML ([login]\Local Settings\Application Data\Macromedia\Flash 8\en\Configuration\Classes\FP8) et y ajouter var idMap:Array. Ce qui reste dangereux si votre code source doit pouvoir être compilé sur une autre machine.
Commentaires
hey Stéphane,
Its the same situation with the setTimeout method in Flash 8, there aren't any references to it in the intrinsic classes.
The other workaround I usually do is use array notation to reference it to avoid the compiler checking it.
trace(xml"idMap""2".attributes.nom);
The advantage of doing it that way is that you can distribute your FLA's without the other developers getting compile errors if they haven't changed their intrinsic classes.
http://www.peterelst.com/blog/2005/12/19/flash-8-settimeout-and-xmlidmap/
Thanks Stéphane ;)
woww thanks téphane Bebrone
thank u