Solved

Flex (as3) add parameters to addEventListener

Posted on 2013-05-11
2
724 Views
Last Modified: 2013-05-13
Hello, I am using this code, can't really also release the asp script(license) that this code requires for the database connections but you get the idea:

mssqlQuery("SELECT * FROM Test_Locations WHERE FID = '"+ MFID +"'","GetFriendInfo");

Open in new window


public function mssqlQuery(sql:String,fid:String):void {
				var http:HTTPService = new HTTPService;
				var parm:Object = new Object;
				parm.fas_sql = sql;
				parm.fas_db = mssql_db; 
				http.url = mssql_url+"?irand="+Math.random();
				http.showBusyCursor = true;
				http.request = sql;
				http.addEventListener(ResultEvent.RESULT, mssqlResult);
				http.addEventListener(FaultEvent.FAULT, mssqlFault);
				http.method = "POST";
				sqlToken = http.send(parm);
				sqlToken.param = fid;
			}
			
			private function mssqlFault(event:FaultEvent):void {
				var err:String = event.fault.faultString;
				trace(err);
			}
			
			/********************************************************
			 * mssqlResult() should be used to handle all of the
			 * returns of your queries. This will end up being a 
			 * long case list.
			 * 
			 *********************************************************/
			
			private function mssqlResult(event:ResultEvent):void{
				
				//Note: All Results are stored in the
				// event.result object
				
				//Create a new case/break for each of your
				//sql query statements
				
				var directionList:ArrayCollection;
				var countdrac:int = 0;
				switch(event.token.param){
					case "GetFriendInfo":
						if (event.result && event.result.results && event.result.results.record && (event.result.results.record.length > 0)){
							FriendsPopMap(currentuserhandling.name, "http://graph.facebook.com/"+currentuserhandling.id+"/picture", event.result.results.record.Place, event.result.results.record.Personal, event.result.results.record.CurrentUpdateInterval)
							currentuserhandling = null;
							trace("ran");
						}
						break;
					
					case "SetMyInfo":
						//just sends data out no response needed
						
						break;	
					
				}	
			}

Open in new window


The problem is that the mssqlQuery is called from a 'for each' statement that reads from facebook API(gets facebook id's from all of your friends), then if the FID(their facebook ID) is in my database it will mark them on a map(FriendsPopMap), the problem is that since the mssqlQuery takes more time I can't store the current other userinfo(that comes from facebook) in currentuserhandling as the facebook runs faster then the mssqlQuery, I wan't to maybe add parameters to the mssqlQuery and also the mssqlResult  so it can get the extra data from facebook, that is not stored in my database(script above only connects to my database).
0
Comment
Question by:JoachimPetersen
  • 2
2 Comments
 
LVL 29

Expert Comment

by:dgofman
Comment Utility
0
 
LVL 29

Accepted Solution

by:
dgofman earned 500 total points
Comment Utility
But for anserwing on your question describing in the titile: "Flex (as3) add parameters to addEventListener"

You can use my function:

public static function FunctionParaUtil(callBack:Function, ...args:Array):Function{
				var handler:Function;
				handler = function(event:Event):void{
					var func:Function = arguments.callee.prototype.func;
					var args:Array = arguments.callee.prototype.args;
					func.apply(null, [event].concat(args));
				};
				handler.prototype.func = callBack;
				handler.prototype.args = args;
				return handler;
}	

Open in new window


now you can change addEventListener call

var parm:Object = new Object;
				parm.fas_sql = sql;
				parm.fas_db = mssql_db; 
				http.url = mssql_url+"?irand="+Math.random();
				http.showBusyCursor = true;
				http.request = sql;
				http.addEventListener(ResultEvent.RESULT, FunctionParaUtil(mssqlResult, parm));

Open in new window


And your "mssqlResult" event handler function will able two receive to parameters

private function mssqlResult(event:ResultEvent, parm):void{
       for(var name:String in param)
            trace(name + "="+ param[name]);
}
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This is intended to introduce all collision detection principles in flash, their strengths, weaknesses and workarounds. The main method for Collision Detection in flash is using hitTestObject. But unless you'll be pushing rectangular shapes without …
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now