打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
VB+Flash通讯归纳
用的VB6+AS2

在VB中可以随意画一个ShockwaveFlash命名为MYFLASH
在Form_Load()中把要载入的FLASH写上
MYFLASH.Movie = "http://...book.swf"
MYFLASH.Menu = False
MYFLASH.Playing = False//在VB中这些参数修改应该比较好看明白.
MYFLASH.Move 0, 0, 1024 * Screen.TwipsPerPixelX, 768 * Screen.TwipsPerPixelY //定义了一个1024*768的尺寸.

下面讲一下VB调用FLASH中的函数
VB中建个按钮:but 加入以下点击事件
Private Sub but1_Click(Index As Integer)
MYFLASH.CallFunction "<invoke name=""win""  returntype=""xml""></invoke>"
End Sub
这里就用CallFunction 来调用FLASH中的函数"win"这里用XML形式调用这个是无参数函数
要是带参数的话就写成CallFunction "<invoke name=""win""  returntype=""xml""><arguments><string>hello</string><string>world</string></arguments></invoke>"
在FLASH处:
function win():Void{
        
        };
flash.external.ExternalInterface.addCallback("win", this, win);  //这个是一定要写的.在AS3中不是这样写的.这是AS2的写法.不多讲了(也讲不明白)自己查一下吧.

VB修改FLASH中的变量.
MYFLASH.SetVariable "shuru_txt.text", "123123"//这里还可以改动态文本内容
MYFLASH.SetVariable "aa", "123123--123123"//这里是直接改变量

好了,其它相关的参数和方法打下VB都有意思很明白也简单,不太会出错.我觉得能调用函数和改变量就很强了.:-156)

==============================================================================
client要与flash交互,只要使用以下3个函数:

HRESULT CallFunction([in] BSTR request, [out, retval] BSTR* response);
HRESULT SetReturnValue([in] BSTR returnValue);
void FlashCall([in] BSTR request);

CallFunction和SetReturnValue是IShockwaveFlash接口中定义的。
FlashCall是_IShockwaveFlashEvents接口中定义的。

CallFunction
CallFunction的作用是由client调用flash中函数,request参数是一个xml,包含了要调用的函数名和参数,response是flash函数的返回值,也是同样格式的xml。 
FlashCall
_IShockwaveFlashEvents是一个连接点,当flash调用client时,就会调用此接口中的FlashCall。参数request和CallFunction中的request一样,也是一个xml,包含函数名和参数。 
SetReturnValue
FlashCall是没有返回值的,那么当client通过FlashCall被调用时,如何返回某些数据呢,就通过SetReturnValue函数。SetReturnValue的参数returnValue同样是个xml,但只是request格式xml的一个节点。 
xml格式
xml格式如下:
<invoke name="foo" returntype="xml">
    <arguments>
        <number>10</number>
        <string>hello flash</string>
    </arguments>
</invoke>
invoke节点是根节点,name属性是要调用的函数名returntype属性必须为"xml"。
arguments下是参数列表,这个例子中是一个number型参数和一个string型参数。
CallFunction和FlashCall的参数都是这种格式的xml,但SetReturnValue的参数只是arguments下面一个子节点,例如"<number>10</number>"。 
flash支持的参数类型
flash支持的参数类型如下:
  AS class/value c++ class/value format comments 
null NULL <null/>   
Boolean true bool true <true/>   
Boolean false bool false <falsh/>   
String BSTR <string>string value</string>   
Number int/double <number>-12</number>
<number>3.14</number>   
Array(元素可以是混合类型) 允许混合类型元
素的集合,如vector<VARIANT> <array>
  <property id="0">
    <number>3.14</number>
  </property>
  <property id="2">
    <string>string value</string>
  </property>
  ...
</array> property 节点定义各个元素,而 id 属性为从 0 开始的数值索引。 
Object 含有字符串键和
对象值的字典,
如map<string, VARIANT> <object>
  <property id="name">
    <string>John Doe</string>
  </property>
  <property id="age">
    <string>33</string>
  </property>
  ...
</object> property 节点定义各个属性,而 id 属性为属性名称(字符串)。 
其它内置或自定义的类   <null/>

<object></object> ActionScript 将其它对象编码为 null 或空对象。不管是哪种情况,所有属性值都会丢失。 

这里要注意,flash穿出的参数不区分整型和符点型,因此需要自己对number类型做判断,比如可以查找如果value中包含'.',就说明是符点型
===========================================================================
相关资料链接
http://bbs.blueidea.com/thread-2939674-1-1.html
也就是在VB中做好js格式数据,用JS向AS转递数据方法。
VB端
Private Sub Command1_Click()
       Flash1.CallFunction "<invoke name=""show""  returntype=""xml""><arguments><string>hello</string><string>world</string></arguments></invoke>"    '篇幅关系,与上面同行
End Sub
Private Sub Form_Load()
    ShockwaveFlash1.LoadMovie 0, App.Path & "\showstring.swf"
End Sub
flash端
①添加一个文本框text_txt以显示效果
②ActionScript代码为
function show(str1:String,str2:String):Void{
      test_txt.text=str1+" : "+str2;
}
flash.external.ExternalInterface.addCallback("show",this,show);

同理
http://support.teamdev.com/thread/3196
http://bbs.blueidea.com/thread-2787764-1-1.html

'VB

   Case "CallUserData" '**********获取用户下拉列表数据
        'rctUser.Close
        Call ExcuteSql(rctUser, "select * from cn_user") '获取用户表记录集
        Dim strUsername, strUserid
        For i = 1 To rctUser.RecordCount '循环条件为用户(参赛队伍)的数量
        rctUser.AbsolutePosition = i '设置当前记录号
        strUsername = strUsername & rctUser.Fields(2).Value & "$" '构建XML字串 用户名
        strUserid = strUserid & rctUser.Fields(0).Value & "$" '构建XML字串 对应ID
        Next
         strUsername = Mid(strUsername, 1, Len(strUsername) - 1)  '删除XML串后的$号
         strUserid = Mid(strUserid, 1, Len(strUserid) - 1) '删除XML串后的$号
            strXmlop = "<invoke name=""UserData""returntype=""xml""><arguments>" '定义XML开始语句 name 后定义调用函数名
            swf.CallFunction strXmlop & "<string>" & strUsername & "</string><string>" & strUserid & "</string>" & strXmled
    rctUser.Close





'FLASH



//自定义函数区
//**********************************列表显示队伍名称 Uname:队伍名称 Uid:对应ID
function UserData(Uname:String, Usid:String):Void {
       username.splice(0);
       userid.splice(0);
       username = Uname.split("$");
       //以$标识侵害字符串
       userid = Usid.split("$");
       _root.login.user.removeAll();
       //清空下拉列表
       for (i=0; i<username.length; i++) {
              //循环赋值到下拉列表框
              _root.login.user.addItem({data:userid, label:username});
       }
}

//事件侦听器定义区
flash.external.ExternalInterface.addCallback("UserData", this, UserData);
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
flash与client交互
AS3与JS通讯
MFC中使用FLASH相关
.net面试题大全(有答案)
为大家详细介绍VB.NET使用FindWindow方法
【转】C#与FLASH的完美结合
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服