AS3与JavaScript之间的通讯

准确的来说应该是AS3与JavaScript之间的通讯,其通讯的机理就是:ExternalInterface,具体的使用方法在Flex或Flash的使用帮助里都有详细的说明。

JavaScript发送变量到AS:

Flex:

ExternalInterface.addCallback(”setBoxArea”,receivedFromJavaScript);

private function receivedFromJavaScript(value:String):void {
Alert.show(value);
}

HTML:

function setBox(o) { thisMovie(”lc”).setBoxArea(”hello”); }

AS发送变量到JavaScript:

Flex:

var wrapperFunction:String = “getChartData”;
var o:Object = new Object();
o.chartType = “line”;
o.yField = yFieldCB.selectedItem;
s = ExternalInterface.call(wrapperFunction,o);
Alert.show(s);

HTML:

function getChartData(o) {
alert(o);
return o.chartType+o.yField;
}
转自:http://bruce-peng.iteye.com/admin/blogs/new
阅读更多

没有更多推荐了,返回首页