The way filtering works on imeem is by using a keyword followed by a semi-colon, which is used as a prefix to the search query. For example, filtering a query of "elvis presley" by artist will produce the following as the final query to be sent to imeem "artist:elvis presley", without the quotes. If no fiter is specified, then the query is simply whatever the user typed in. In our little application, we'll have the 3 filter types as mentioned above. So let's get started!
Open up the project, and make sure you have imeemMusicExtension.mxml open in Design View. From the toolbox, drag a RadioButtonGroup control onto the stage. Upon doing that, you should see something like this. Name the control rdgFilter. Add 3 radio buttons as in the screen shot. Give each one a label (Artist, Album, Any). Also, make sure you set the Selected property to true for the "Any" option, like this. It'll be the default filter. Drag a label control and position it right above the radio button group - as in the above screen shot.
Now, switch to Source View. For each radio button, set the "value" property - as in this screen shot. That is, set value="artist:" for the Artist radio button; for Album, set value="album:"; for Any, set value="". On the mx:RadioButtonGroup, add the following:
change="rdgFilter_change(event)"
All filtering will be handled by that method - whenever the user changes the filtering.
Still in Source View, let's write the code to make it all happen. First, here's how things will work:
- upon application load, we will disable the filter (radio button group)
- upon displaying the search results (for the first time), we will enable the filter (with Any being the default)
- when users change the selected option, we will grab the Value of the chosen option and prepend it to whatever the user typed in
- we will call the search method with the new query (filter + user input)
rdgFilter.enabled = false;
Next, let's create the method rdgFilter_change.
private function rdgFilter_change(e:Event) : void {
var rbg : RadioButtonGroup = e.target as RadioButtonGroup;
var rb : RadioButton = rbg.selection;
txtQuery.text = rb.value.toString() + txtQuery.text.replace(/artist:/g, "").replace(/album:/g, "");
search_click(null);
}
When the user changes the filtering, the above method will be called. We extract the chosen option and store that into the RadioButton variable rb. We then remove any previous filter (artist: or album:) from the input textbox by using regular expressions. Next, we prepend the value of the chosen filtering option to what the user typed in. And finally, we call the search_click method, which will send the filtered query to imeem.
The final step is to enable the filtering control when the search results are loaded. That happens inside the onMediaSearch method. Locate that method, and add this right before the last line of code:
rbgFilter.enabled = true;
The altered code looks like this. You can now run the application to see it work!
Here's what I got for each filtering option: default (any), by artist, by album (and no query).
That's all there is to it! Users can now filter search results through the application. In the next tutorial, I will show you how to add the Duration field in the search results. I think it's important to see how long a song is!
Stay tuned!
Published by Wagz Lu
- Getting Started with Adobe Flex 2Flex by Adobe is one of those products that can be used by both designers and developers without making either group feel left out or left behind.
- Social Networking: A Brief Overview An introduction to the world of social networking
- Guide to the Best Applications for Palm CentroThe new Palm Centro (available on both Sprint and AT&T) has a great catalog of games and applications to make further enhance your slick new Smartphone.
- The True Potential of the Internet: A Critical Look at Facebook and the Human Tech...The True Potential of the Internet: A Critical Look at Facebook and the Human Tech Ladder
Adobe Flex, Future for Web and Graphic Design?A short but honest review on what I think about the RIA technology - Adobe Flex
- In Business You Need to Write
- ThinkFree Online Software: Web-based Java Applications Come of Age
- How to Write Songs
- 5 Tips on How to Stay Motivated to Write
- Guide on How to Write an Employee Manual
- ProfileLinker Launches and Lets Users Sync Profiles Across Social Networking Sites
- Flex 2: Software Development Kit for Rich Internet Applications Aimed for Flash Pl...



