 				{
 					var instance:Object = getSingletonInstance(theInterface);
 					var classInfo:Object = describeTypeJSON(theInterface, DescribeType.INCLUDE_TRAITS | DescribeType.INCLUDE_METHODS | DescribeType.HIDE_NSURI_METHODS | DescribeType.USE_ITRAITS);
-					// add a callback for each external interface function
+					// register each external interface function
 					for each (var methodInfo:Object in classInfo.traits.methods)
-						generateExternalInterfaceCallback(instance, methodInfo);
+						new ExternalMethod(instance, methodInfo);
 				}
 
 				var prev:Boolean = ExternalInterface.marshallExceptions;

			
			// Try to get the JSON interface - if not available, settle with the flawed ExternalInterface.call() parameters feature.
			// If a parameter is an Object, we can't trust ExternalInterface.call() since it doesn't quote keys in object literals.
			// For example, if you give {"Content-Type": "foo"} as a parameter, ExternalInterface generates the following invalid
			// object literal: {Content-Type: "foo"}.
			try {
				json = getDefinitionByName("JSON");
			} catch (e:Error) { }

			// concatenate all code inside a function wrapper
			code = 'function(' + pNames.join(',') + '){\n' + code + '}';
			
			// work around bug where ExternalInterface does not escape backslash.
			code = code.split('\\').join('\\\\');
			
			// if there are no parameters, just run the code
			if (pNames.length == 0)
				return ExternalInterface.call(code);
