[原]client通過ActiveX與flash互動方法簡介
阿新 • • 發佈:2019-02-06
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://www.cnblogs.com/maconel/archive/2010/09/29/1838743.html