Passing data / variables from a Visual Basic form to a Flash object

I am pretty sure that this can be answered somewhere here on stackOverflow, but I have no options with this.

I have a VisualBasic form with a button object on it. I would like this button to have an onClick procedure to click it, moving the variable or another command to another window in which the Shockwave Flash movie works. (For example, on an ActionScript file in Flash, there is a function to display some text in Flash Video that is launched when called.)

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

0
source share
1 answer

To do this, use the ExternalInterface class in AS3. It allows you to transfer data between the AS3 and the host application / container (be it a web page or a VB form, etc.).

On the AS3 side, you set it like this:

 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); } 

On the host side, you send / receive XML to an ActiveX object.

Your XML is as follows:

 <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 create this XML in VB and call the CallFunction method of the Flash VB object, passing it the xml string.

 Dim returnValue As String returnValue = MyFlashShockWaveObj.CallFunction(xml) MsgBox(returnValue) 'hello from flash 

If you transfer a lot of objects, sometimes it’s easiest to just JSON. Build them and pass only one JSON string to AS3 (and / or vice versa).

+1
source

Source: https://habr.com/ru/post/1233985/


All Articles