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