Flex与JavaScript的交互
Flex 与 JavaScript 交互,主要依靠Flex的ExternalInterface,其提供了addCallBack和call方法.
下面的例子将演示Flex调用javascript,和javascript调用Flex。
js 代码
-------------------------------------------------------------------------------------------------------------
function hello(param) {
alert(param);
return "jsp Hello:" + param;
}
function callFlexFunction() {
var x = document.getElementById("flexObject").flexHelloWorld("Hello", "world");
alert(x);
}
html代码
--------------------------------------------------------------------------------------------------------------
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553537800"
width="640" height="378" id="flexObject">
<param name="allowScriptAccess" value="always" />
<embed src="Test.swf" mce_src="Test.swf" width="640" height="378"
name ="flexObject" play="true" loop="false"
allowScriptAccess="sameDomain"
type="application/x-shockwave-flash"
pluginspage="http://www.adobe.com/go/getflashplayer">
</embed>
</object>
Flex 代码
--------------------------------------------------------------------------------------------------------------
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"
initialize="initApp()">
<mx:Script>
<![CDATA
import mx.controls.Alert;
public function flexHelloWorld(param1:String, param2:String):String {
Alert.show("param1: " + param1 + "; param2:" + param2);
return "Hello " + param1 + param2;
}
public function initApp():void {
ExternalInterface.addCallback("flexHelloWorld", flexHelloWorld);
}
p
相关文档:
此例展示了如何在 Flex 4 中为 Halo 控件设置旧的 Halo 皮肤,而不是新的 Spark 皮肤。
<?xml version="1.0" encoding="utf-8"?>
<!-- http://www.slsay.com/archives/131 -->
<s:Application name="Spark_Halo_theme_test"
xmlns:fx="http://ns.adobe.com/mxml/2009"
&nbs ......
flex代码:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo" minWidth="1024" minHeight="768">
<fx:Script>
<!--[CDATA[
i ......
自定义控件中的页面代码:
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="wcontrol.ascx.cs" Inherits="wcontrol" %>
<script type ="text/javascript">
function PopupCalendar(InstanceName)
{
///Global Tag
this.instanceName=InstanceName;
///Properties
this.separator="-"
t ......