Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/actionscript-3/7.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C#Flash回调的简单示例_C#_Actionscript 3_Flash - Fatal编程技术网

C#Flash回调的简单示例

C#Flash回调的简单示例,c#,actionscript-3,flash,C#,Actionscript 3,Flash,我正在尝试编写一个简单的命令行C#程序,该程序调用已编译的Flash ActionScript 3.0中的函数,然后显示字符串输出。在我可以使用的SWF文件中已经注册了一个回调函数 经过一些研究(),这是我到目前为止得到的: using AxShockwaveFlashObjects; using System; namespace ConsoleProg { class ConsoleProg { static void Main (string[] args) {

我正在尝试编写一个简单的命令行C#程序,该程序调用已编译的Flash ActionScript 3.0中的函数,然后显示字符串输出。在我可以使用的SWF文件中已经注册了一个回调函数

经过一些研究(),这是我到目前为止得到的:

using AxShockwaveFlashObjects;
using System;

namespace ConsoleProg {
    class ConsoleProg {
        static void Main (string[] args) {
            string path = "container.swf";
            AxShockwaveFlash flash = new AxShockwaveFlash();
            flash.LoadMovie(0, path);
            string result = flash.CallFunction("<invoke name=\"api_function\" returntype=\"xml\"><arguments></arguments></invoke>");
            Console.WriteLine(result);
        }
    }
}
我做的另一件事是将console程序剥离到一个对象中,并在其自己的线程中实例化它,明确指定其单元状态:

using AxShockwaveFlashObjects;
using System.Threading;
using System;

namespace ConsoleProg {
    class ConsoleProg {
        public string path;

        public ConsoleProg (string path) {
            this.path = path;
        }

        public void LoadFlash() {
            AxShockwaveFlash flash = new AxShockwaveFlash();
            flash.LoadMovie(0, this.path);
            string result = flash.CallFunction("<invoke name=\"api_function\" returntype=\"xml\"><arguments></arguments></invoke>");
            Console.WriteLine(result);
        }

        static void Main (string[] args) {
            ConsoleProg cp = new ConsoleProg("api_container.swf");

            Thread t = new Thread(cp.LoadFlash);
            t.SetApartmentState(ApartmentState.STA);
            t.Start();
        }
    }
}
使用AxShockWaveLashObject;
使用系统线程;
使用制度;
名称空间控制台日志{
类控制台日志{
公共字符串路径;
公共控制台日志(字符串路径){
this.path=path;
}
公共void LoadFlash(){
AXSHOCKWAVELASH闪存=新AXSHOCKWAVELASH();
flash.LoadMovie(0,this.path);
字符串结果=flash.CallFunction(“”);
控制台写入线(结果);
}
静态void Main(字符串[]参数){
ConsoleProg cp=新的ConsoleProg(“api_container.swf”);
线程t=新线程(cp.LoadFlash);
t、 SetApartmentState(ApartmentState.STA);
t、 Start();
}
}
}
这与我上面的另一次尝试给出的错误相同

在这一点上,我不知所措。我做错了什么?如果有人能给我举一个简单但完整的例子,这将非常有帮助,因为我在网上看到的所有教程都是代码片段,我无法将它们汇编成可以工作的东西


我需要程序做的就是在控制台中打印flash文件输出的字符串。这应该是一个更大的程序的一部分,但现在我只想让一个简单的例子起作用。

我的一个项目就是这样做的,所以我将与您分享一些代码片段,以帮助您。 首先,确保您的项目构建目标是x86。我根本无法让x64或任何CPU工作。 谁知道呢,这可能会解决你所有的问题

如果没有,请尝试使用我从项目中借用的代码执行函数调用:

public string InvokeFlashFunction(string functionName, params object[] functionParameters)
{
    //Creates the xml that will be sent to the flash movie
    XmlDocument invokeDocument = new XmlDocument();
    //Creates the invoke element that will be the root element of the xml
    XmlElement rootElement = invokeDocument.CreateElement("invoke");
    //Set both attributes of the invoke element
    rootElement.SetAttribute("name", functionName);
    rootElement.SetAttribute("returnType", "xml");
    //Creates the arguments element
    XmlElement childNode = invokeDocument.CreateElement("arguments");
    //foreach parameter, creates a child node to the arguments element
    foreach (object param in functionParameters)
    {
        XmlElement paramNode = GetParamXml(param, invokeDocument);
        //appends the parameters
        childNode.AppendChild(paramNode);
    }
    //Appends the arguments node
    rootElement.AppendChild(childNode);
    //Call the function
    return _FlashMovie.CallFunction(rootElement.OuterXml);
}
您可以这样使用它:

InvokeFlashFunction("api_function", "your arguments here");

我不确定swf是否可以用作util控制台程序。基本上,它只能在Flash播放器中工作。您不能只是按原样启动swf文件(就像您在控制台应用程序中所做的那样),然后等待来自它的某些信息。
InvokeFlashFunction("api_function", "your arguments here");