Comments on: Ways to use E4X to filter data in ActionScript 3 https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/ Archive of older blog posts written by Josh Tynjala about Flash, Flex, and ActionScript Wed, 26 Jun 2013 02:52:46 +0000 hourly 1 https://wordpress.org/?v=4.9.9 By: LEx https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-53743 Mon, 03 Dec 2012 10:05:22 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-53743 Need a book with more information on this, who is happy with only a few random bits of code like this ?

anyone know a good book on A4X ????

]]>
By: Shakey https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-50321 Sat, 08 Sep 2012 20:58:23 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-50321 Great article, really useful for me to get up-to-speed on the stuff I’ve been missing out on for so long.

One thing that would be really useful for me would be an E4X equivalent of SQL’s IN command, in that I want to create a filter based on a collection I’ve generated previously.

Example:
I have a bunch of “zone” nodes that contain “userid” children, which hold a numeric value. I also have a bunch of “person” nodes with an “id” attribute.

For a given “zone” node, I get an XMLList of the values of all the “userid” child nodes. I want to use this this to return the “person” nodes whos “id” attribute matches the IDs stored in the list.

In simpler terms, the E4X equivalent of

SELECT person
FROM people
WHERE id IN (x,y,z,…)

I have no problem at all just looping through the collection and doing an E4X filter for each, I was just wondering if there’s a more elegant way of doing it.

Again, great articles – thanks!

]]>
By: Bertv https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-50300 Fri, 24 Aug 2012 06:50:29 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-50300 Excelent post!

I modified the addUniqueValue function a little so it will also deal with multiple child elements.

private function addUniqueValue(value:Object, list:XMLList):XMLList{
	for (var i:int=0;i<value.length();i++){
		if(!list.contains(value[i]))
		{
			list += value[i];
		}
	}
	return list;
}
]]>
By: AS3/E4X: Rekursiv alle Unterknoten mit einem Attribut finden / crusy.net https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-5283 Tue, 08 Mar 2011 13:47:48 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-5283 […] ist. Man beachte: Den doppelten Punkt hinter “xml”, sowie den Sternchen-Selektor. Quelle, man beachte auch die unten verlinkten weiterführenden […]

]]>
By: Auzzie https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-550 Sat, 06 Feb 2010 19:23:07 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-550 Great post, I was able to use a couple of scripts above but ran into an issue and was wondering if anyone had some insight:

I have some data that I separated into labels of a combobox:


Features3
Features1,Features2,Features3
Features2,Features3
Features1
—-
if (featuresCombo.selectedLabel != item.FEATURES)
return false;

return true;
—-

If you select ‘Features3’ for example it doesn’t return the selections that have multiple entries separated by commas.

Is there a way to filter based on the occurance of a string rather than matching the whole string?

I tried to use the (contains) function from above and was getting this error:Error #1123: Filter operator not supported on type mx.utils.ObjectProxy.

Thanks for any help.
-Auzzie

]]>
By: Kristin https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-549 Mon, 25 Jan 2010 18:21:30 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-549 By the way, while I’m here… I’m trying to write a picture viewer program and I’ve seen a lot of tuts on the web, but they don’t seem to address my needs. I have 3 xml elements: name, file (an image), and comments. I have so many image files that I’ve chosen to load them into a list component which I can load up with name data. For some reason I’ve hit a road block in that I don’t know how to link the selectedItem in the list box so I can display the other elements on the page. I hope this isn’t too complicated a question to ask. Thanks

]]>
By: Kristin https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-548 Mon, 25 Jan 2010 18:14:07 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-548 Thanks Josh, that was it and I should have tried it. I only had intro classes to Flash MX2004 and that’s been almost 3 years ago. Kinda rusty.

]]>
By: Josh Tynjala https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-546 Mon, 25 Jan 2010 06:27:02 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-546 Put the trace() call after the loop and you might see the correct result. During the loop, it’s still filtering by field name and value, and that means it will search over each of the items more than once.

]]>
By: Kristin https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-545 Mon, 25 Jan 2010 06:13:45 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-545 Hey, great article, but I’ve run into a snag with your last example. I cut and pasted your code and get this in my output window:

(your code and your xml file which I swear I did not change)

var filtered:XMLList = data.item;
var fields:Array = [{name: "source", value: "Amazon"}, {name: "price", value: "599.99"}];
       
var fieldCount:int = fields.length;
for(var i:int = 0; i <fieldCount; i++)
{
    var fieldName:String = fields[i].name;
    var fieldValue:String = fields[i].value;
    filtered = filtered.(child(fieldName) == fieldValue);
	trace(filtered);
}

this code is supposed to return Amazon items worth 599.99, however it returns 3 Amazon items. It's returning 2-599.99 items and 1-399.99 item which is not what's in the xml file.

output results

Amazon
399.99

Amazon
599.99

Amazon
599.99

I’m new to xml and AS3 so I wanted to make sure this wasn’t happening because I’m using Flash CS4 (since your original post is almost 3 years old)

]]>
By: Josh Tynjala https://joshblog.net/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-544 Thu, 21 Jan 2010 21:56:55 +0000 http://www.zeuslabs.us/2007/05/08/methods-to-filter-data-with-e4x-in-flash-9/#comment-544 Jon, if you have multiple elements as children, it might not be possible to do it in a single statement. You might have to put source into an XMLList and search that separately.

However, you might also look at contains() on XMLList. It might be useful here. I’ve never played with that one, though.

]]>