AS3 : Tool for freelancers

You have computing skills and you are looking for a little job online? The best solution for you is to go to a freelancer website like rentacoder or getafreelancer.

But there is a problem : their interface are awful and you cannot see all the lastest jobs and the price that is offered for it on just one page, so here is my solution : An AS3 script that connects to these sites and gather you the important informations and the link to the offers page.

These lines of code can also help you to get your head into the AS3 if you want to learn how to make XML requests and simple animations with ActionScript3.

Please don’t juge me too hard, i’m not as good as I would like to be in this language!

package{
	import flash.display.Sprite;
	import flash.display.MovieClip;
	import flash.xml.*;
	import flash.net.URLLoader;
	import flash.net.URLRequest;
	import fl.controls.DataGrid;
	import flash.text.TextField;
	import fl.controls.dataGridClasses.DataGridColumn;
	import fl.events.DataGridEvent;
	import fl.transitions.Tween;
	import fl.transitions.easing.*;
	import flash.text.TextFormat;
	import fl.containers.ScrollPane;
	import fl.controls.Button;

	public class main extends Sprite{
		var mystream:URLLoader = new URLLoader();
		var mystream2:URLLoader = new URLLoader();
		var entriesDG:DataGrid = new DataGrid();
		var rectMC:MovieClip = new MovieClip();
		var popupText:TextField = new TextField();

		public function main(){
			var myrequest:URLRequest = new URLRequest("http://www.rentacoder.com/RentACoder/misc/LinkToUs/RssFeed_newBidRequests.asp")
			var myrequest2:URLRequest = new URLRequest("http://www.getafreelancer.com/rss.xml");
			mystream.load(myrequest);
			mystream2.load(myrequest2);
			mystream.addEventListener("complete",parseIt);
			mystream2.addEventListener("complete",parseIt2);
			entriesDG.width = 530;
			entriesDG.height = 360;
			entriesDG.x = 10;
			entriesDG.y = 10;
			entriesDG.editable = true;
			entriesDG.addEventListener(DataGridEvent.ITEM_EDIT_BEGIN,gridlistener);
			var datec:DataGridColumn = new DataGridColumn("Date");
			datec.width = 150;
			entriesDG.addColumn(datec);
			var salaryc:DataGridColumn = new DataGridColumn("Max Salary");
			salaryc.sortOptions = Array.NUMERIC;
			salaryc.width = 80;
			entriesDG.addColumn(salaryc);
			var titlec:DataGridColumn = new DataGridColumn("Title");
			titlec.width = 300;
			entriesDG.addColumn(titlec);
			addChild(entriesDG);

			var reloadBtn:Button = new Button();
			reloadBtn.label = "Reload";
			reloadBtn.y = 374;
			reloadBtn.x = 230;
			reloadBtn.addEventListener("click",function(e){
				entriesDG.removeAll();
				myrequest = new URLRequest("http://www.rentacoder.com/RentACoder/misc/LinkToUs/RssFeed_newBidRequests.asp")
				mystream.load(myrequest)
				parseIt(e)
			})
			addChild(reloadBtn);
			var square:Sprite = new Sprite();
			rectMC.addChild(square);
			square.graphics.beginFill(0x0000FF);
			square.graphics.drawRoundRect(0,10,600,380,50);
			square.graphics.endFill();
			square.alpha = 1;
			rectMC.x = 540;
			addChild(rectMC);
			popupText.width = 490;
			popupText.height = 400;
			popupText.x = 35;
			popupText.y = 35;
			popupText.wordWrap = true;

			rectMC.addChild(popupText)
			rectMC.addEventListener("click",foldPopup);
		}
		public function parseIt(e)
		{
			var curxml:XML = XML(mystream.data);
			var lines:Array = new Array;
			for each (var entry in curxml.channel.item)
			{
				var subObj:Object = new Object();
				subObj.title = entry.title;
				subObj.link = entry.link;
				subObj.date = entry.pubDate;
				subObj.description = entry.description;
				lines.push(subObj);
			}
			display(lines)
		}
		public function parseIt2(e)
		{
			var curxml:XML = XML(mystream2.data);
			var lines:Array = new Array;
			for each (var entry in curxml.channel.item)
			{
				var subObj:Object = new Object();
				subObj.title = entry.title;
				subObj.link = entry.link;
				subObj.date = entry.pubDate;
				subObj.description = entry.description;
				lines.push(subObj);
			}
			display2(lines)
		}
		public function display(entries:Array)
		{
			entriesDG.sortItemsOn("Date",  Array.DESCENDING);
			var pos = 0;
			for each (var entry in entries)
			{
				var textline:TextField = new TextField();
				var explosion:Array = entry.title.split('--');
				var priceStr:String = explosion.pop().replace("Max Bid: ","");
				explosion.pop();
				var priceInt:int;
				priceInt = int(Number(priceStr.replace(",","").replace("\x24","")))

				if(priceInt == 0)
				{
					priceInt = 1000000;
				}
				var temptitle:TextField = new TextField();
				var tempTF:TextField = new TextField();
				tempTF.htmlText = explosion.join(", ");
				entriesDG.addItem({"Max Salary":priceInt,"Title":tempTF.text,"Date":String(entry.date).replace(" EST",""),"description":entry.description,"link":entry.link});
			}
		}
		public function display2(entries:Array)
		{
			entriesDG.sortItemsOn("Date",  Array.DESCENDING);
			var pos = 0;
			for each (var entry in entries)
			{
				var budgetRegExp:RegExp = /Budget: \$[0-9]+\-([0-9]+)/;
				var catches:Object = budgetRegExp.exec(entry.description);
				var salary;
				if(catches)
				{
					salary = catches[1];
				}
				else
				{
					salary = 1000000;
				}
				entriesDG.addItem({"Max Salary":salary,"Title":entry.title,"Date":String(entry.date).replace(" -0400",""),"description":entry.description,"link":entry.link});
			}
		}
		public function gridlistener(e:DataGridEvent)
		{
			var ev:DataGridEvent = e
			var curEl = entriesDG.getItemAt(int(ev.rowIndex));
			var curtf:TextFormat = new TextFormat();
			curtf.color = 0xFFFFFF;
			curtf.size = 15;
			popupText.htmlText = curEl.description+"\n\rGo to the site";
			popupText.setTextFormat(curtf);
			popupText.autoSize = "left";

			var myTweenX:Tween = new Tween(rectMC, "x", Back.easeInOut, 540, 10, 1, true);
		}
		public function foldPopup(e)
		{
			var myTweenX:Tween = new Tween(e.currentTarget, "x", Back.easeInOut, e.currentTarget.x, 540, 1, true);
		}
	}
}

Leave a Reply

Your email address will not be published. Required fields are marked *