Featured Posts

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Flex Assets/File Manager – ASP VBScript - Version... I recently built a JavaScript file manager but I wanted more control and better usability instead of expanding on the JavaScript version I decided to build it using Flex....

Readmore

Getting at your SQL Database using Flex and .NET Web ServicesGetting at your SQL Database using Flex and .NET Web... So you gave up on trying to figure out how you can directly connect Flex to your database like with any server side language and decided to Google the answer. Well by now...

Readmore

Adobe Flex - Filter XML Data using E4X and RegExp Have you ever you wanted to filter your data like you would using the SQL LIKE condition? Well with E4X and RegExp you too can reap the benefits of pattern matching! Here...

Readmore

Fitchett Rss

Adobe Flex – Filter XML Data using E4X and RegExp

Posted on : 09-05-2009 | By : Michael Fitchett | In : ActionScript, Development, Flex

2


Here is an example

The Flash plugin is required to view this object.

Here is the code for the example

<!--
=====================================================================================
	Get data using HTTPService from fitchett.me RSS Feed
=====================================================================================
-->
 
<!--
=====================================================================================
	Script
=====================================================================================
-->
 
		<![CDATA[
 
			private function init():void
			{
				//Once all of the components have loaded send the HTTPService request
				myData.send();
			}
 
			private function dataLoaded():void
			{
				//Once the data has loaded populate the DataGrid and TextArea with the Results.
				myDataGrid.dataProvider = myData.lastResult.channel.item;
			}
 
			private function search():void
			{
				try
				{
					var reg:RegExp = new RegExp(tbSearch.text.toLowerCase());
					myDataGrid.dataProvider = myData.lastResult.channel.item.(reg.test(title.toLowerCase()))
				}
				catch(err:Error)
				{
					//Do Nothing...
				}
				finally
				{
					//Do Nothing...
				}
			}
 
		]]>
 
<!--
=====================================================================================
	Display Components
=====================================================================================
-->

You can download the project source here Flex E4X Example (716)

For those of you wondering how this example was done without reading the code read on…

Getting the Data

  1. Flex gets the XML data from the RSS feed using the HTTPService
  2. Once the data has successfully loaded the data is then passed into the DataGrid

Filtering the Data using E4X and RegExp

  1. When a user types into the textbox a change action is triggered triggering the search() function
  2. The search() function then runs code that creates a new RegExp variable named “reg”with the “tbsearch.text.toLowerCase()”being passed in as the string.
  3. The DataGrid provider is then … umm iono man it’s just magic to me at this point.
  4. And poof everything works!

Ok maybe I do know.

5. Since we are using E4X we parse the XML using the new RegExp we just created.

As always ping me if you have questions with a comment or feel free to e-mail me michael@fitchett.me

http://www.fitchett.me/wp-content/plugins/sociofluid/images/digg_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/delicious_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/technorati_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/google_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/myspace_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/facebook_32.png http://www.fitchett.me/wp-content/plugins/sociofluid/images/twitter_32.png

Comments (2)

MICHAEL!

Awesome stuff. You totally rock! Thank you very much for posting this.

As many experienced Flex developers have pointed out, using E4X to work with XML data in Flex is supposed to be the most efficient approach. However, very few people have shown me any actual examples of getting all of this to work.

So, I’m especially grateful to you for a) taking the time to put together an example and b) being generous enough to share it with the rest of the world.

Finally, I always kid around with other developers and tell them that [insert your favorite programming language] is all bout knowing the syntax. After that, it’s programming as usual. So when I went back to my original code, I seriously had to make two syntax changes, and everything started working. I wonder, are we Flex developers like golfers? Coming back to it, time after time, to get a little better each time and figure out new techniques to keep things interesting?

At any rate, A BIG THANK YOU for all your work and help.

I really appreciate your contribution, I took me a while to figure out how to compare strings with E4X using a regular expression and not only the == comparator.

Thanks a lot.

Write a comment

Anti-Spam Protection by WP-SpamFree

Advertise Here