问题
I'm pretty sure that this can be answered somewhere here on stackOverflow but I'm out of options with this.
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.)
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.
回答1:
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).
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);
}
From the host side, you send/recieve XML to the ActiveX object.
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>
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
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).
来源:https://stackoverflow.com/questions/31736018/passing-data-variable-from-a-visual-basic-form-to-a-flash-object