将数据/变量从 Visual Basic 表单传递到 Flash 对象

问题描述:

我很确定可以在 * 上的某个地方回答这个问题,但我对此无能为力.

I'm pretty sure that this can be answered somewhere here on * but I'm out of options with this.

我有一个带有按钮对象的 VisualBasic 表单.我希望该按钮具有 onClick 过程,以便单击它会将变量或其他命令传递到另一个运行 Shockwave Flash电影"的窗口.(例如,Flash 文件的 ActionScript 上有一个函数,可以在调用时在运行的 Flash Video 中显示一些文本.)

I have a VisualBasic form with an button object on it. I would like that button to have an onClick procedure so that clicking it passes a variable or other command to another window which has a Shockwave Flash "movie" running. (For example, there is a function on the ActionScript of the Flash file to display some text in the Flash Video running when invoked.)

我缺少什么才能使这成为可能?我知道这是关于 fscommand 但不确定如何从 VB 传递变量.

What am I missing to make this possible? I know it's something about the fscommand but not sure how to pass a variable from VB with it.

这样做的方法是使用 ExternalInterface 类.它允许在 AS3 和宿主应用程序/容器(网页或 VB 表单等)之间传递数据.

The way to do this is using the ExternalInterface class in AS3. It allows data to be passed between AS3 and the host application/container (be that a webpage or a VB Form etc).

在AS3端,你设置如下:

In the AS3 side, you set it up as follows:

function myAS3Function(someNumber:Number, someObject:Object)
{
    //do something with your number and object
    trace(someObject.isAwesome);

    return "hello from AS3";
}

//register your function with a label VB can call/invoke
if (ExternalInterface.available){
   ExternalInterface.addCallback("myAS3Function", myAS3Function);
}

从主机端,您 到 ActiveX 对象.

From the host side, you send/recieve XML to the ActiveX object.

您的 XML 如下所示:

Your XML looks like this:

<invoke name="myAS3Function" returntype="xml">
    <arguments>
        <number>5</number>
        <object>
            <property id="foo"><string>bar</string></property>
            <property id="isAwesome"><true/></property>
        </object>
    </arguments>
</invoke>

现在,在 VB 中构造该 XML,并调用 VB flash 对象的 CallFunction 方法,将 xml 字符串传递给它.


Now, construct that XML in VB, and invoke the CallFunction method of the VB flash object, passing it the xml string.

Dim returnValue As String
returnValue = MyFlashShockWaveObj.CallFunction(xml)

MsgBox(returnValue) 'hello from flash

如果您要传递大量对象,有时最简单的方法是将它们 JSON.stringify 并将一个 JSON 字符串传递给 AS3(和/或返回).

If you are passing a lot of objects, sometimes it easiest to just JSON.stringify them and pass just one JSON string over to AS3 (and/or back).