Passing data/variable from a Visual Basic form to a Flash Object

前端 未结 1 1099
深忆病人
深忆病人 2021-01-16 20:38

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.

1条回答
  •  南笙
    南笙 (楼主)
    2021-01-16 20:48

    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:

    
        
            5
            
                bar
                
            
        
    
    

    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).

    0 讨论(0)
提交回复
热议问题