你可以调用Html页面中的JavaScript,通过与JavaScript的交互,可以改变Style,调用远程方法。还可以将数据传递给Html页
面,处理后再返回给Flex,完成这样的功能主要有两种方法:ExternalInterface()和navigateToUrl()。
在Flex调用JavaScript最简单的方法是使用ExternalInterface(),可以使用此API调用任意JavaScript,传递参
数,获得返回值,如果调用失败,Flex抛出一个异常。ExternalInterface封装了对浏览器支持的检查,可以用available属性来查
看。ExternalInterface的使用非常简单,语法如下:
flash.external.ExternalInterface.call(function_name:String[,arg1,...]):Object
参数function_name是要调用的JavaScript的函数名,后面的参数是JavaScript需要的参数。
As代码
ExternalInterface.call(FUNCTION_USEREXIT)
ExternalInterface.addCallback("checkExit",checkExit)
privatestaticvarFUNCTION_USEREXIT:String="document.insertScript=function()"+"
{"+"window.onbeforeunload=function()"+"{"+"varflexObj=MarineDataEdit.checkExit()
"+"if(flexObj!="")"+"{"+"returnflexObj"+"}else{"+"return"+"}"+"}"+"}"
publicfunctioncheckExit():String{varuserExitStr:String="你如果现在离开,则您的所有信息将失效!"
returnuserExitStr
ExternalInterface.call(FUNCTION_USEREXIT)
ExternalInterface.addCallback("checkExit",
checkExit)privatestaticvarFUNCTION_USEREXIT:String="document.insertScript=function()"+"
{"+"window.onbeforeunload=function()"+"{"+"varflexObj=MarineDataEdit.checkExit()
"+"if(flexObj!="")"+"{"+"returnflexObj"+"}else{"+"return"+"}"+"}"+"}"
publicfunctioncheckExit():String{varuserExitStr:String="你如果现在离开,则您的所有信息将失效!"
returnuserExitStr
其中ExternalInterface类的addCallback函数是调用AS端的返回值。
flex属性:属性包括:flexDirection,justifyContent,alignItems,flexWrap
属性包括:flex,alignSelf
以下介绍会使用到一些代码和图片,先定义两个简单组件,方便理解
//定义一个默认半径为20,颜色为#527fe4的圆组件
var Circle = React.createClass({
render : function(){
var size = this.props.size || 20
var color = this.props.color || '#527fe4'
return <View style={{backgroundColor:color,borderRadius:size/2,height:size,width:size,margin:1}}/>
},
})