我目前正在构建一个flash程序(swf文件),我已经在Python中创建了函数和命令。是他们将我的Python命令导入Flash CC的方法,例如:在我的Flash程序中按下按钮时执行我的Python命令?
我已经在互联网和Stackoverflow.com上搜索了一个答案。我知道pyamf,但我不知道如何使用它,我真的不认为这是我正在寻找的。 p>
答案 0 :(得分:0)
在AS3中运行外部代码的唯一方法是使用AIR,为此你需要编译python代码并将exe文件放在一些地方并使用本机进程运行它并与之通信。此代码可能会对您有所帮助。
_exepath part是从python代码编译的exe文件的地址。
import flash.events.EventDispatcher;
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.ProgressEvent;
import flash.events.NativeProcessExitEvent;
import flash.filesystem.File;
import flash.events.Event;
public class ProcessRequest extends EventDispatcher {
private var _np:NativeProcess;
private var _npi:NativeProcessStartupInfo;
private var _args:Vector.<String>;
private var exePath:String;
private var _windowsPath:String;
public var _output:String;
public function ProcessRequest(_exePath:String) {
exePath = _exePath;
}
public function process(input_arg:Vector.<String>):void {
_args = input_arg;
_process();
}
private function _process():void {
_npi = new NativeProcessStartupInfo();
_npi.executable = File.applicationDirectory.resolvePath(exePath);
_npi.arguments = _args;
_np = new NativeProcess();
_np.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
_np.addEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
_np.addEventListener(NativeProcessExitEvent.EXIT, onExit);
_np.start(_npi);
}
private function onOutputData(e:ProgressEvent):void {
_output = String(_np.standardOutput.readUTFBytes(_np.standardOutput.bytesAvailable));
dispatchEvent(new Event("OutputData"));
}
private function onErrorData(e:ProgressEvent):void {
_output = String(_np.standardError.readUTFBytes(_np.standardError.bytesAvailable));
dispatchEvent(new Event("ErrorData"));
}
private function onExit(e:NativeProcessExitEvent):void {
_np.removeEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
_np.removeEventListener(ProgressEvent.STANDARD_ERROR_DATA, onErrorData);
_np.removeEventListener(NativeProcessExitEvent.EXIT, onExit);
_npi = null;
_np = null;
_args = null;
dispatchEvent(new Event(Event.COMPLETE));
}
public function Cancel():void {
_np.exit(true);
}
}