I’m working on my first real Flex app and i have learned a lot by it. Now I’m trying to understand the basics of working with classes. I have a function that asks information from the LastFm API. This is the base function:
public function zoekChart(event:MouseEvent):void
{
var api_URL:String = 'http://ws.audioscrobbler.com/2.0/';
var api_method:String = 'geo.getMetroUniqueArtistChart';
var api_key:String = '99f1f497c0bd598f1ec20571a38e2219';
var country:String = countryText.text;
var metro:String = metroText.text;
var limit:String = '5';
api_request = api_URL + '?method=' + api_method + '&country=' + country + '&metro=' + metro + '&api_key=' + api_key + '&limit=' + limit;
myRequest.send();
}
Now I’m trying to make a class which does the same as the function. This is what i have so far:
package valueObjects
{
public class Kevin_myChart
{
private var api_URL:String;
private var api_method:String;
private var api_key:String;
private var country:String;
private var metro:String;
private var limit:String;
public function lastFMCall (api_URL:String, api_method:String, api_key:String,
country:String, metro:String, limit:String)
{
this.api_URL=api_URL;
this.api_method=api_method;
this.api_key=api_key;
this.country=country;
this.metro=metro;
this.limit=limit;
}
public function getInfo(size:String):String
{
return api_URL + '?method=' + api_method + '&country=' + country + '&metro=' + metro + '&api_key=' + api_key + '&limit=' + limit;
}
}
}
Is this a good start? My first question is how i can import the values of textfields countryText and metroText in the class.
Also, how should I continue from here? How can i make sure that my application will be able to use the functions declared in the class and how can i get values in the class’s vars now?
You can use your class’s
constructorto pass the values. A constructor is called when you create a new instance of your class.Your
Kevin_myChartclass with constructor:Your getting in the right direction, maybe this tutorial will give you some more info about the way a class is build.
http://www.kirupa.com/developer/as3/classes_as3_pg3.htm
Otherwise a quick Google Search could help you further aswell.