The easiest way to assign IDs to controls is to use the Design View. So switch to Design View and click on each control to assign IDs to them. For label 1, ID=lblPrompt; label2, ID=lblResult; text input, ID=txtQuery; button, ID=btnSearch; datagrid, ID=dgResults.
For now, we'll show only 3 pieces of information about the search results - in our datagrid:
- Title
- Artist
- Album
headerText="Title" dataField="title"/>
headerText="Artist" dataField="artist"/>
headerText="Album" dataField="album"/>
Note that the values for dataField are all lowercase; it has to be that way! While in Source View, locate the mx:button line and add this: click="search_click(event)". Also, add this to the mx:Application line (at the very top): creationComplete="onInit()". Like so.
What do these 2 things do? We specify that the method search_click should be called when the search button is clicked, and the method onInit should be called when the application is [fully] loaded. When the application is fully loaded, we'll set the stage for interaction with imeem. We'll define those 2 methods shortly, but first let's get some pre-requisites in place.
We need to import some classes from the imeem library so we can use the methods from the API. Also, we need some variables like api key and secret. So right before the closing tag for mx:Application, start by typing the mx:Script tag and then hit Enter; the closing tag should automatically be typed for you, including the CDATA section.
Inside the CDATA section (view screen shot), type the following:
import imeem.api.Imeem;
import imeem.api.data.MusicData;
import imeem.api.results.ResultData;
private var imeemService:Imeem = null;
static private const API_KEY:String = "YOUR API KEY";
static private const API_SECRET:String = "YOUR SECRET";
//will be called once application is fully loaded
private function onInit() : void {
imeemService = new Imeem(API_KEY, API_SECRET);
}
//will be called when search button is clicked
private function search_click(evt:Event) : void {
imeemService.media.search(txtQuery.text, "music", 0, 100, onMediaSearch);
}
//will be called with the results of the search, will display data in datagrid control
private function onMediaSearch(result:ResultData) : void {
dgResults.dataProvider = result.data.results;
}
Insert your API key and Secret above and run the application. Here's what the script section looks like: view screen shot.
Let's explain. In the first 3 lines, we import the necessary classes to interact with the API. Then we declare some variables that'll be used throughout the application. In the first method, we instantiate the required Imeem object that'll give us access to the various classes - including media, users, and playlists. The API key and Secret are required for the instantiation; Imeem needs them to verify our application.
In the second method, we use the search method of the media class to query imeem for music matching the keyword typed by the user. Also, we pass the default values for offset (0) and number of results (100). Offset is used for paging. The last argument is a method (a callback method), which will be called with the results of the search.
In that callback method (last method), we extract the data out of the argument (result) and bind the datagrid to the dataset.
Did you run the application? Did you get any results? If so, it must be getting exciting! I ran my version and got this: view screen shot.
It'll get even more exciting as we add more functionalities to the application. In the next tutorials of the series, we'll add the Login function and allow users to add songs to their existing playlists.
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.
Top Ten Applications Every Linux User Should HaveMany software applications are not compatible with Linux, because they have a different user interface and different functionalities. There are, however, some very powerful appl...- How to Organize Your College ApplicationsIf you want to avoid the stress of the application process, and if you're worried about keeping all of that paperwork straight, follow these tips on how to organize your college applications.
- 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.
Creating Brand Exposure and Marketing Buzz by Using Twitter, a Popular S...If you want to get a brand recognition and create exposure; it's an effective tool to engage others' interest. Therefore creating a buzz and free marketing for your company.
- ThinkFree Online Software: Web-based Java Applications Come of Age
- Medicare and Social Security: How Social Programs Can Help You Help Your Elderly P...
- Using the Social Security Death Index for Genealogy Research
- Replacement Social Security Card's Put a Strain on US Citizens
- Social/Business Networking-ProfileJunky
- ProfileLinker Launches and Lets Users Sync Profiles Across Social Networking Sites
- Flex 2: Software Development Kit for Rich Internet Applications Aimed for Flash Pl...
- how to use adobe flex to write applications
- how to write application using imeem media platform
- how to program social applications in actionscript



