假设我已经知道了密码。无论如何,我可以在C Sharp中添加密码参数,以便与要求输入密码的actionscript客户端进行通信。我想在C Sharp中编码密码,这样当我登录客户端时它会自动输入密码。
答案 0 :(得分:0)
由于Flash的构建方式,当您使用Flash Player或Flash Lite时,这是不可能的(AFAIK)。但是,使用Flash平台可以使用Adobe AIR(用于桌面和移动应用程序)完成类似的操作。为了实现以下方法,您需要发布“扩展桌面”的AIR应用程序。
为了使其正常工作,您的C Sharp程序需要是命令行。输入一些命令行提示符(例如“READY”)后,需要在一行输出密码。
您需要使用NativeProcess(documentation)从Adobe AIR应用程序启动C Sharp程序。
以下代码是我自己的工作类的修改版本。我不保证错误,因为我删除了几个专有元素。前两个需要作为自定义类存在于同一个包中。它们保存在的文件夹必须与相关的.FLA处于同一级别,并且与包名称具有相同的名称。
CUSTOM EVENT CLASS:
package myCustomPackage
{
import flash.events.Event;
public class NativeProcessEvent extends Event
{
public static const ON_RECEIVE:String = "onReceive";
public var customMessage:String = "";
public function NativeProcessEvent(type:String, bubbles:Boolean=false, cancelable:Boolean=false):void
{
super(type, bubbles, cancelable);
}
}
}
NATIVEPROCESS CLASS(这是沟通):
package myCustomPackage
{
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.ProgressEvent;
import flash.utils.ByteArray;
import flash.filesystem.File;
import flash.events.EventDispatcher;
import myCustomPackage.NativeProcessEvent
public class nativeProcessChannel extends EventDispatcher
{
var startup:NativeProcessStartupInfo = new NativeProcessStartupInfo();
var file:File = new File();
var process:NativeProcess = new NativeProcess();
private var mEvt:NativeProcessEvent;
var buffer:Array = [];
//Constructor
public function nativeProcessChannel()
{
file = File.applicationDirectory.resolvePath("mypasswordprogram.exe");
if(file.exists && NativeProcess.isSupported)
{
startup.executable = file;
process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, addToBuffer);
process.start(startup);
}
else if(!file.exists)
{
trace("ERROR: Cannot find program.");
}
else
{
trace("ERROR: NativeProcess not supported.");
}
}
//Sends a line of input to the command line.
public function send(msg:String):void
{
process.standardInput.writeUTFBytes(msg + "\n");
}
function addToBuffer(event:ProgressEvent):void
{
var bytes:ByteArray = new ByteArray();
process.standardOutput.readBytes(bytes, 0, process.standardOutput.bytesAvailable);
buffer.push(bytes.toString());
mEvt = new NativeProcessEvent("onReceive");
mEvt.customMessage = "NativeProcess message received.";
dispatchEvent(mEvt);
}
//Receives a line of output from the command line
public function receive():String
{
var r:String = "";
if(buffer.length > 0)
{
r = buffer[0]
buffer.splice(0,1);
}
return r;
}
//This closes the connection, freeing memory.
public function close():void
{
process.exit();
}
}
}
实现:
import myCustomPackage.NativeProcessClass;
import myCustomPackage.NativeProcessEvent;
var myProcess:NativeProcessClass = new NativeProcessClass();
myProcess.addEventListener(NativeProcessEvent.ON_RECEIVE, continueGetPassword);
//This function is necessary so you can reuse the NativeProcess channel.
public function reconnect()
{
myProcess = new NativeProcessClass();
myProcess.addEventListener(NativeProcessEvent.ON_RECEIVE, continueGetPassword);
}
public function getPassword()
{
myProcess.send("READY");
}
public function continueGetPassword()
{
var password:String = myProcess.receive();
//You now have the password from your c-sharp program. Do with it what you like!
myProcess.close()
reconnect();
}
据我所知,由于其安全限制,没有其他方法可以使用Flash连接到另一个程序。 Adobe AIR中的扩展桌面是唯一无法获取沙盒的基于Flash的平台。
希望这会有所帮助(并为任何代码错误道歉。)