VB6 與 AS2之間的數(shù)據(jù)通訊,AS3類同
2008年的時候我在百度知道上已經(jīng)回答過,你亦說你看過這帖了,但你說還不明白 那我就詳細地說一下吧http://zhidao.baidu.com/question/43875593.html?si=1
flash發(fā)送數(shù)據(jù)到容器 javascript(面向網(wǎng)頁)中一般推薦使用 flash.external.ExternalInterface.call
但在VB(或其它的語言中),一般建議使用fscommand(command, args)這種方式來通訊 ,
在VB端(其它就是基于shockwaveFlash控件的內(nèi)部事件 其它VC Delphi類同)
有一個這樣的針對swf 控件的事件處理子過程
Private Sub ShockwaveFlash1_FSCommand(ByVal command As String, ByVal args As String)
'具體看看形參就知道 如何跟 flash中的 fscommand函數(shù)格式對應(yīng)了
Select Case command
Case "play"
Case "stop"
End Select
End Sub
flash -> VB的通訊 就像上面這樣
通過 select case 來判斷分支多個command的操作
而重要的是 VB -> flash方面的使用
一般的SetVariable這種方法 或者 使用 flashVars來傳入?yún)?shù),都是基于很被動的方式動作,即設(shè)置了值 ,如果flash方面不主動檢測的話,就不會引發(fā)其它相關(guān)的動作
所以一般推薦使用基于事件處理的 callFunction方式
swf控件.callFunction xml格式數(shù)據(jù)
xml格式數(shù)據(jù)的構(gòu)成是
<invoke name="flash里面的偵聽名" returntype="xml"><arguments><string>數(shù)據(jù)</string></arguments></invoke>
要發(fā)送的數(shù)據(jù)需要使用 <數(shù)據(jù)類型></數(shù)據(jù)類型> 包裹
相關(guān)的類型說明詳見 http://www.cnblogs.com/maconel/archive/2010/09/29/1838743.html
但一般使用默認的String就足夠了 包括數(shù)值數(shù)據(jù)也可以用它發(fā)送
這是最基本的數(shù)據(jù)格式 即可以這樣寫
swf控件.callFunction <invoke name=""flash里面的偵聽名""returntype=""xml""><arguments><string>數(shù)據(jù)</string></arguments></invoke>
'<string>數(shù)據(jù)</string> 這里設(shè)置要發(fā)送的字符數(shù)據(jù)
而flash方面要寫的as代碼
as2:
flash.external.ExternalInterface.addCallback("flash里面的偵聽名",this, funcCall);
function funcCall(str1:String):Void{
//這里的str1對應(yīng)第一個參數(shù) 就是 數(shù)據(jù)
//如果有多個參數(shù) 依次在這里形參聲明
//傳入的數(shù)據(jù)可以在flash里任意處理
}
as3:
//as2和as3中的 ExternalInterface對象的 addCallback函數(shù)原型有所不同 這里不用添加this指向
flash.external.ExternalInterface.addCallback("flash里面的偵聽名", funcCall);
function funcCall(str1:String):void{
//這里的str1對應(yīng)第一個參數(shù) 就是 數(shù)據(jù)
//如果有多個參數(shù) 依次在這里形參聲明
}
這里為了方便 整理出一個vb端的發(fā)送代碼 直接調(diào)用封裝好的方法就可以發(fā)送數(shù)據(jù)
復(fù)制內(nèi)容到剪貼板
[ 本帖最后由 HSZZLZL 于 2011-1-11 11:43 編輯 ]
代碼:
Private Sub Form_Load()
ShockwaveFlash1.Movie = App.Path & "\as2.swf"
'下面這是必須的格式 使用 getStr函數(shù)為傳入的字符串兩邊加上<String></String>
'getCallFuncStr函數(shù)為已經(jīng)格式好的 參數(shù)對添加上頭尾的xml格式聲明
'CWScallFunc 重構(gòu)調(diào)用swf控件的方法 派發(fā)數(shù)據(jù)
Dim str As String
str = getStr("strUsername") & getStr("strUserid") '這里傳入兩個參數(shù)
CWScallFunc ShockwaveFlash1, getCallFuncStr("UserData", str)
End Sub
Private Sub ShockwaveFlash1_FSCommand(ByVal command As String, ByVal args As String)
Select Case command
Case "trace"
MsgBox args
End Select
End Sub
Private Function getStr$(v$)
'時間關(guān)系 這里只設(shè)置默認的string 如有更多數(shù)據(jù)類型需要 可參看http://www.cnblogs.com/maconel/archive/2010/09/29/1838743.html
'自行擴展
getStr = IIf(v <> "", "<string>" & v & "</string>", "")
End Function
Private Function getCallFuncStr$(FuncName$, Optional v$ = "")
'=======此參數(shù) FuncName$需與flash端偵聽名同步
Dim strXmlop, strXmled As String
strXmlop = "<invoke name=""" & FuncName & """returntype=""xml""><arguments>" '定義XML開始語句 name 后定義調(diào)用函數(shù)名
strXmled = "</arguments></invoke>"
getCallFuncStr = strXmlop & v & strXmled
End Function
Private Sub CWScallFunc(obj As ShockwaveFlash, v$)
'重構(gòu)
obj.CallFunction v
'如果報 callfunction IShockwaveFlash 失敗 基本就沒救了 flash10的問題
End Sub
posted on 2011-04-19 15:55 aiaiwoo 閱讀(569) 評論(0) 編輯 收藏 所屬分類: ASP/Visual Basic