⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 flash.js

📁 对java中如何使用Ajax技术
💻 JS
📖 第 1 页 / 共 3 页
字号:
	//	specific way in which this communication occurs,	//	presenting a common interface to JavaScript irrespective of the underlying	//	Flash version.	if(dojo.flash.useFlash6()){		this._writeFlash6();	}else if (dojo.flash.useFlash8()){		this._writeFlash8();	}}dojo.flash.Communicator.prototype = {	_writeFlash6: function(){		var id = dojo.flash.obj.id;				// global function needed for Flash 6 callback;		// we write it out as a script tag because the VBScript hook for IE		// callbacks does not work properly if this function is evalled() from		// within the Dojo system		document.writeln('<script language="JavaScript">');		document.writeln('  function ' + id + '_DoFSCommand(command, args){ ');		document.writeln('    dojo.flash.comm._handleFSCommand(command, args); ');		document.writeln('}');		document.writeln('</script>');				// hook for Internet Explorer to receive FSCommands from Flash		if(dojo.render.html.ie){			document.writeln('<SCRIPT LANGUAGE=VBScript\> ');			document.writeln('on error resume next ');			document.writeln('Sub ' + id + '_FSCommand(ByVal command, ByVal args)');			document.writeln(' call ' + id + '_DoFSCommand(command, args)');			document.writeln('end sub');			document.writeln('</SCRIPT\> ');		}	},		_writeFlash8: function(){		// nothing needs to be written out for Flash 8 communication; 		// happens automatically	},		//Flash 6 communication.		// Handles fscommand's from Flash to JavaScript. Flash 6 communication.	_handleFSCommand: function(command, args){		//dojo.debug("fscommand, command="+command+", args="+args);		// Flash 8 on Mac/Firefox precedes all commands with the string "FSCommand:";		// strip it off if it is present		if(command != null && !dojo.lang.isUndefined(command)			&& /^FSCommand:(.*)/.test(command) == true){			command = command.match(/^FSCommand:(.*)/)[1];		}		 		if(command == "addCallback"){ // add Flash method for JavaScript callback			this._fscommandAddCallback(command, args);		}else if(command == "call"){ // Flash to JavaScript method call			this._fscommandCall(command, args);		}else if(command == "fscommandReady"){ // see if fscommands are ready			this._fscommandReady();		}	},		// Handles registering a callable Flash function. Flash 6 communication.	_fscommandAddCallback: function(command, args){		var functionName = args;					// do a trick, where we link this function name to our wrapper		// function, _call, that does the actual JavaScript to Flash call		var callFunc = function(){			return dojo.flash.comm._call(functionName, arguments);		};					dojo.flash.comm[functionName] = callFunc;				// indicate that the call was successful		dojo.flash.obj.get().SetVariable("_succeeded", true);	},		// Handles Flash calling a JavaScript function. Flash 6 communication.	_fscommandCall: function(command, args){		var plugin = dojo.flash.obj.get();		var functionName = args;				// get the number of arguments to this method call and build them up		var numArgs = parseInt(plugin.GetVariable("_numArgs"));		var flashArgs = new Array();		for(var i = 0; i < numArgs; i++){			var currentArg = plugin.GetVariable("_" + i);			flashArgs.push(currentArg);		}				// get the function instance; we technically support more capabilities		// than ExternalInterface, which can only call global functions; if		// the method name has a dot in it, such as "dojo.flash.loaded", we		// eval it so that the method gets run against an instance		var runMe;		if(functionName.indexOf(".") == -1){ // global function			runMe = window[functionName];		}else{			// instance function			runMe = eval(functionName);		}				// make the call and get the results		var results = null;		if(!dojo.lang.isUndefined(runMe) && runMe != null){			results = runMe.apply(null, flashArgs);		}				// return the results to flash		plugin.SetVariable("_returnResult", results);	},		// Reports that fscommands are ready to run if executed from Flash.	_fscommandReady: function(){		var plugin = dojo.flash.obj.get();		plugin.SetVariable("fscommandReady", "true");	},		// The actual function that will execute a JavaScript to Flash call; used	// by the Flash 6 communication method. 	_call: function(functionName, args){		// we do JavaScript to Flash method calls by setting a Flash variable		// "_functionName" with the function name; "_numArgs" with the number		// of arguments; and "_0", "_1", etc for each numbered argument. Flash		// reads these, executes the function call, and returns the result		// in "_returnResult"		var plugin = dojo.flash.obj.get();		plugin.SetVariable("_functionName", functionName);		plugin.SetVariable("_numArgs", args.length);		for(var i = 0; i < args.length; i++){			// unlike Flash 8's ExternalInterface, Flash 6 has no problem with			// any special characters _except_ for the null character \0; double			// encode this so the Flash side never sees it, but we can get it 			// back if the value comes back to JavaScript			var value = args[i];			value = value.replace(/\0/g, "\\0");						plugin.SetVariable("_" + i, value);		}				// now tell Flash to execute this method using the Flash Runner		plugin.TCallLabel("/_flashRunner", "execute");				// get the results		var results = plugin.GetVariable("_returnResult");				// we double encoded all null characters as //0 because Flash breaks		// if they are present; turn the //0 back into /0		results = results.replace(/\\0/g, "\0");				return results;	},		// Flash 8 communication.		// Registers the existence of a Flash method that we can call with	// JavaScript, using Flash 8's ExternalInterface. 	_addExternalInterfaceCallback: function(methodName){		var wrapperCall = function(){			// some browsers don't like us changing values in the 'arguments' array, so			// make a fresh copy of it			var methodArgs = new Array(arguments.length);			for(var i = 0; i < arguments.length; i++){				methodArgs[i] = arguments[i];			}			return dojo.flash.comm._execFlash(methodName, methodArgs);		};				dojo.flash.comm[methodName] = wrapperCall;	},		// Encodes our data to get around ExternalInterface bugs.	// Flash 8 communication.	_encodeData: function(data){		// double encode all entity values, or they will be mis-decoded		// by Flash when returned		var entityRE = /\&([^;]*)\;/g;		data = data.replace(entityRE, "&amp;$1;");				// entity encode XML-ish characters, or Flash's broken XML serializer		// breaks		data = data.replace(/</g, "&lt;");		data = data.replace(/>/g, "&gt;");				// transforming \ into \\ doesn't work; just use a custom encoding		data = data.replace("\\", "&custom_backslash;&custom_backslash;");				data = data.replace(/\n/g, "\\n");		data = data.replace(/\r/g, "\\r");		data = data.replace(/\f/g, "\\f");		data = data.replace(/\0/g, "\\0"); // null character		data = data.replace(/\'/g, "\\\'");		data = data.replace(/\"/g, '\\\"');				return data;	},		// Decodes our data to get around ExternalInterface bugs.	// Flash 8 communication.	_decodeData: function(data){		if(data == null || typeof data == "undefined"){			return data;		}				// certain XMLish characters break Flash's wire serialization for		// ExternalInterface; these are encoded on the 		// DojoExternalInterface side into a custom encoding, rather than		// the standard entity encoding, because otherwise we won't be able to		// differentiate between our own encoding and any entity characters		// that are being used in the string itself		data = data.replace(/\&custom_lt\;/g, "<");		data = data.replace(/\&custom_gt\;/g, ">");				// Unfortunately, Flash returns us our String with special characters		// like newlines broken into seperate characters. So if \n represents		// a new line, Flash returns it as "\" and "n". This means the character		// is _not_ a newline. This forces us to eval() the string to cause		// escaped characters to turn into their real special character values.		data = eval('"' + data + '"');				return data;	},		// Sends our method arguments over to Flash in chunks in order to	// have ExternalInterface's performance not be O(n^2).	// Flash 8 communication.	_chunkArgumentData: function(value, argIndex){		var plugin = dojo.flash.obj.get();				// cut up the string into pieces, and push over each piece one		// at a time		var numSegments = Math.ceil(value.length / 1024);		for(var i = 0; i < numSegments; i++){			var startCut = i * 1024;			var endCut = i * 1024 + 1024;			if(i == (numSegments - 1)){				endCut = i * 1024 + value.length;			}						var piece = value.substring(startCut, endCut);						// encode each piece seperately, rather than the entire			// argument data, because ocassionally a special 			// character, such as an entity like &foobar;, will fall between			// piece boundaries, and we _don't_ want to encode that value if			// it falls between boundaries, or else we will end up with incorrect			// data when we patch the pieces back together on the other side			piece = this._encodeData(piece);						// directly use the underlying CallFunction method used by			// ExternalInterface, which is vastly faster for large strings			// and lets us bypass some Flash serialization bugs			plugin.CallFunction('<invoke name="chunkArgumentData" '														+ 'returntype="javascript">'														+ '<arguments>'														+ '<string>' + piece + '</string>'														+ '<number>' + argIndex + '</number>'														+ '</arguments>'														+ '</invoke>');		}	},		// Gets our method return data in chunks for better performance.	// Flash 8 communication.	_chunkReturnData: function(){		var plugin = dojo.flash.obj.get();				var numSegments = plugin.getReturnLength();		var resultsArray = new Array();		for(var i = 0; i < numSegments; i++){			// directly use the underlying CallFunction method used by			// ExternalInterface, which is vastly faster for large strings			var piece = 					plugin.CallFunction('<invoke name="chunkReturnData" '															+ 'returntype="javascript">'															+ '<arguments>'															+ '<number>' + i + '</number>'															+ '</arguments>'															+ '</invoke>');																		// remove any leading or trailing JavaScript delimiters, which surround			// our String when it comes back from Flash since we bypass Flash's			// deserialization routines by directly calling CallFunction on the			// plugin			if(piece == '""' || piece == "''"){				piece = "";			}else{				piece = piece.substring(1, piece.length-1);			}					resultsArray.push(piece);		}		var results = resultsArray.join("");				return results;	},		// Executes a Flash method; called from the JavaScript wrapper proxy we	// create on dojo.flash.comm.	// Flash 8 communication.	_execFlash: function(methodName, methodArgs){		var plugin = dojo.flash.obj.get();						// begin Flash method execution		plugin.startExec();				// set the number of arguments		plugin.setNumberArguments(methodArgs.length);				// chunk and send over each argument		for(var i = 0; i < methodArgs.length; i++){			this._chunkArgumentData(methodArgs[i], i);		}				// execute the method		plugin.exec(methodName);																// get the return result		var results = this._chunkReturnData();				// decode the results		results = this._decodeData(results);				// reset everything		plugin.endExec();				return results;	}}dojo.flash.Install = function(){	// summary: Helps install Flash plugin if needed.	// description:	//	Figures out the best way to automatically install the Flash plugin	//	for this browser and platform. Also determines if installation or	//	revving of the current plugin is needed on this platform.}dojo.flash.Install.prototype = {	needed: function(){ /* Boolean */		// summary:		//	Determines if installation or revving of the current plugin is 		//	needed. 			// do we even have flash?		if(dojo.flash.info.capable == false){			return true;		}		// are we on the Mac? Safari needs Flash version 8 to do Flash 8		// communication, while Firefox/Mac needs Flash 8 to fix bugs it has		// with Flash 6 communication		if(dojo.render.os.mac == true && !dojo.flash.info.isVersionOrAbove(8, 0, 0)){			return true;		}		// other platforms need at least Flash 6 or above		if(!dojo.flash.info.isVersionOrAbove(6, 0, 0)){			return true;		}		// otherwise we don't need installation		return false;	},	install: function(){		// summary: Performs installation or revving of the Flash plugin.				//dojo.debug("install");		// indicate that we are installing		dojo.flash.info.installing = true;		dojo.flash.installing();				if(dojo.flash.info.capable == false){ // we have no Flash at all			//dojo.debug("Completely new install");			// write out a simple Flash object to force the browser to prompt			// the user to install things			var installObj = new dojo.flash.Embed(false);			installObj.write(8); // write out HTML for Flash 8 version+		}else if(dojo.flash.info.isVersionOrAbove(6, 0, 65)){ // Express Install			//dojo.debug("Express install");			var installObj = new dojo.flash.Embed(false);			installObj.write(8, true); // write out HTML for Flash 8 version+			installObj.setVisible(true);			installObj.center();		}else{ // older Flash install than version 6r65			alert("This content requires a more recent version of the Macromedia "						+" Flash Player.");			window.location.href = + dojo.flash.Embed.protocol() +						"://www.macromedia.com/go/getflashplayer";		}	},		// Called when the Express Install is either finished, failed, or was	// rejected by the user.	_onInstallStatus: function(msg){		if (msg == "Download.Complete"){			// Installation is complete.			dojo.flash._initialize();		}else if(msg == "Download.Cancelled"){			alert("This content requires a more recent version of the Macromedia "						+" Flash Player.");			window.location.href = dojo.flash.Embed.protocol() +						"://www.macromedia.com/go/getflashplayer";		}else if (msg == "Download.Failed"){			// The end user failed to download the installer due to a network failure			alert("There was an error downloading the Flash Player update. "						+ "Please try again later, or visit macromedia.com to download "						+ "the latest version of the Flash plugin.");		}		}}// find out if Flash is installeddojo.flash.info = new dojo.flash.Info();// vim:ts=4:noet:tw=0:

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -