Jan
26
2008
E4X Attribute Filter Doesn’t Work In Switch Statements
Posted by: jordan in flash, tags: as3, bug, e4x, flashHere’s a nice gotcha I found a while back when trying to run a filter on some XML data. If you write an attribute filter inside of a switch statement, the query will return null when you assign it to the XMLList variable. If you trace out the query instead of assigning it, it works fine.
switch (anything) {
case "testcase":
var xlData:XMLList = xmlData.Books.Book.(@author == 'Dickens');
break;
}
The above code will fail; apparently the scoping inside of switch statements is broken. There’s a bug report filed already, but it would be nice to see a fix for this.
This has been driving me crazy for days!
Found your site after the bug report gave me better search criteria.
Have you found any solutions other than a giant IF statement?
Nope, I haven’t found anything better, unfortunately. Glad this helped you troubleshoot though!
Well, here’s the solution I came up with – maybe it will help others:
//inside switch
var xml:XMLList = getFilteredXML(myXML.node1.node2, “languag”, “english”);
trace(xml);
//end of switch
private function getFilteredXML(_xml:XMLList, _attr:String, _val:String):XMLList {
return _xml.(attribute(_attr) == _val);
}
Simply takes the E4X filter out of the switch by way of a function call – works well too!
Yeah, this one nailed me today. I am surprised with as much e4x filtering as I use it didn’t nail me earlier.
I didn’t have to use a function to fix, I simply declared the XML variable outside of the switch
var x:XML;
switch(item.name().toString()) {
case “section”:
x = content_data.section.(name == item.@label)[0];
break;
case “page”:
x = content_data.section.page.(name == item.@label)[0];
break;
}
Surround your switch case with { } i.e
switch (anything) {
case “testcase”:{
var xlData:XMLList = xmlData.Books.Book.(@author == ‘Dickens’);
}
break;
}
should fix it.
If you think about it, it kind of makes sense where the error is as inside a filter ‘this’ is scoped to the class however many methods are scoped to the current node thats being filtered. I can imagine the codes quite messy…
Insane!!
I’m so glad I found this and I’m not going mad. The braces solution works great. Of course you can also solve the problem by branching out of the switch statement into a new function too. Thanks!
я так считаю: превосходно!!
познакомиться с австралийцем Барнаул – Барнаул девушка хочет секса по телефону
женщина познакомится с молодым парнем – в Иваново познакомлюсь с китайцем
в Жуковском как познакомиться с хорошим парнем секс знакомства мужчины Жуковский
в Сургуте мальчик на ночь секс: в Сургуте секс с турками
пара познакомится с мужчиной где познакомиться с хорошим парнем
замужние женщины хотят секса в Химках знакомства с иностранцами
где познакомиться в Муроме с хорошим парнем женщина желает познакомиться для секса Муром
познакомиться в Москве с турком: сайт знакомств с богатыми мужчинами
хочу познакомиться с негром Калуга познакомлюсь с нудистами
отец одиночка познакомится: Москва познакомлюсь с парнем 16 лет
познакомлюсь с импотентом в Новошахтинске Новошахтинск международное брачное агентство
познакомлюсь с мужчиной с ребенком Хасавюрт хочу секса в Хасавюрте с мальчиком
девушка познакомится с парнем Липецк – познакомлюсь с мужчиной ребенком
женщина хочет мужчину для секса – познакомлюсь с женатым
познакомлюсь с парнем 17 лет – в Великом Новгороде девушка хочет познакомиться с парнем
Новошахтинск познакомлюсь с замужней – одинокая девушка желает познакомиться
хочу попробывать секс в Волгодонске Глазове с парнем – транс познакомится с парнем
где познакомиться с молодым человеком – Невинномысск познакомлюсь с мужчиной для встреч
познакомлюсь с мужчиной по смс: знакомства с мужчинами для брака в Подольске