`

actionscript ,javascript的相互调用

    博客分类:
  • flex
阅读更多

1.actionscript调用javascript:

html.mxml内容如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
 <mx:Panel x="109" y="47" width="250" height="200" layout="absolute">
  <mx:TextInput x="35" y="23" id="txtName"/>
  <mx:Button x="73" y="73" label="Button" id="btnConnect" click="invokeJavaScript()"/>
  <mx:Label x="35" y="116" width="160" id="lblResult"/>
 </mx:Panel>
 
 <mx:Script>
  <![CDATA[
   import flash.external.ExternalInterface;
   public function invokeJavaScript():void{
    lblResult.text=ExternalInterface.call("returnTheName",txtName.text); //actionscript调用js
         
   }
  ]]>
 </mx:Script>
</mx:Application>

 

html.html内容如下:
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="history/history.css" />
<title></title>
<script src="AC_OETags.js" language="javascript"></script>
<script src="history/history.js" language="javascript"></script>
<style>
body { margin: 0px; overflow:hidden }
</style>
<script language="JavaScript" type="text/javascript">
var requiredMajorVersion = 9;
var requiredMinorVersion = 0;
var requiredRevision = 124;
function returnTheName(a){
 return "success  "+a;
}
</script>
</head>

<body scroll="no">
<script language="JavaScript" type="text/javascript">

var hasProductInstall = DetectFlashVer(6, 0, 65);
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
if ( hasProductInstall && !hasRequestedVersion ) {
 var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
 var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

 AC_FL_RunContent(
  "src", "playerProductInstall",
  "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
  "width", "100%",
  "height", "100%",
  "align", "middle",
  "id", "html",
  "quality", "high",
  "bgcolor", "#869ca7",
  "name", "html",
  "allowScriptAccess","sameDomain",
  "type", "application/x-shockwave-flash",
  "pluginspage", "http://www.adobe.com/go/getflashplayer"
 );
} else if (hasRequestedVersion) {
 
 AC_FL_RunContent(
   "src", "html",
   "width", "100%",
   "height", "100%",
   "align", "middle",
   "id", "html",
   "quality", "high",
   "bgcolor", "#869ca7",
   "name", "html",
   "allowScriptAccess","sameDomain",
   "type", "application/x-shockwave-flash",
   "pluginspage", "http://www.adobe.com/go/getflashplayer"
 );
  } else {
    var alternateContent = 'Alternate HTML content should be placed here. '
   + 'This content requires the Adobe Flash Player. '
    + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    document.write(alternateContent); 
  }

</script>
<noscript>
   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   id="html" width="100%" height="100%"
   codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
   <param name="movie" value="html.swf" />
   <param name="quality" value="high" />
   <param name="bgcolor" value="#869ca7" />
   <param name="allowScriptAccess" value="sameDomain" />
   <embed src="html.swf" quality="high" bgcolor="#869ca7"
    width="100%" height="100%" name="html" align="middle"
    play="true"
    loop="false"
    quality="high"
    allowScriptAccess="sameDomain"
    type="application/x-shockwave-flash"
    pluginspage="http://www.adobe.com/go/getflashplayer">
   </embed>
 </object>
</noscript>
</body>
</html>

----------------------------------------------------------------------------------------------------------------

 

http://www.cnblogs.com/iihe602/archive/2009/08/12/1544206.html

 

javascript   调用actionscript:

 

main.mxml:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="
http://www.adobe.com/2006/mxml" layout="vertical" horizontalAlign="left" backgroundColor="white"
    initialize="init()">

    <mx:Label text="城市名称:"/>

    <mx:List id="cityList" width="200" height="300" dataProvider="{cities}"/>

    <mx:ArrayCollection id="cities">
        <mx:String>北京</mx:String>
        <mx:String>上海</mx:String>
    </mx:ArrayCollection>
   
    <mx:Script>
        <![CDATA[
            private function init(): void
            {
                //注册回调函数供JavaScript调用
                ExternalInterface.addCallback("callActionScript", asFunctionByJs);
            }
           
            private function asFunctionByJs(city: String): void
            {
                cities.addItem(city);               
            }
        ]]>
    </mx:Script>
</mx:Application>

main.html:

<!-- saved from url=(0014)about:internet -->
<html lang="en">

<!--
Smart developers always View Source.

This application was built using Adobe Flex, an open source framework
for building rich Internet applications that get delivered via the
Flash Player or to desktops via Adobe AIR.

Learn more about Flex at http://flex.org
// -->

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<!--  BEGIN Browser History required section -->
<link rel="stylesheet" type="text/css" href="history/history.css" />
<!--  END Browser History required section -->

<title></title>
<script src="AC_OETags.js" language="javascript"></script>

<!--  BEGIN Browser History required section -->
<script src="history/history.js" language="javascript"></script>
<!--  END Browser History required section -->

<style>
body { margin: 0px; overflow:hidden }
</style>
<script language="JavaScript" type="text/javascript">
<!--
// -----------------------------------------------------------------------------
// Globals
// Major version of Flash required
var requiredMajorVersion = 9;
// Minor version of Flash required
var requiredMinorVersion = 0;
// Minor version of Flash required
var requiredRevision = 124;
// -----------------------------------------------------------------------------
// -->
</script>

<script type="text/javascript">
    function callActionScript(value)
    {
    alert("hehe"); //这个function是自已加的,别的代码是flex自动生成的
        //根据id获取flash实例,在这里id是CallAsFromJs,可以从Embed
        var flash = (navigator.appName.indexOf ("Microsoft") !=-1)?window["main"]:document["main"];
        alert(window["main"]);
        //调用ActionScript注册的回调方法
        flash.callActionScript(value);
    }
</script>
</head>

<body scroll="no">
输入城市名称:<input type="text" id="newCityName"/><input type="button" value="添加城市" onclick="callActionScript(newCityName.value);"/>
<script language="JavaScript" type="text/javascript">
<!--
// Version check for the Flash Player that has the ability to start Player Product Install (6.0r65)
var hasProductInstall = DetectFlashVer(6, 0, 65);

// Version check based upon the values defined in globals
var hasRequestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);

if ( hasProductInstall && !hasRequestedVersion ) {
 // DO NOT MODIFY THE FOLLOWING FOUR LINES
 // Location visited after installation is complete if installation is required
 var MMPlayerType = (isIE == true) ? "ActiveX" : "PlugIn";
 var MMredirectURL = window.location;
    document.title = document.title.slice(0, 47) + " - Flash Player Installation";
    var MMdoctitle = document.title;

 AC_FL_RunContent(
  "src", "playerProductInstall",
  "FlashVars", "MMredirectURL="+MMredirectURL+'&MMplayerType='+MMPlayerType+'&MMdoctitle='+MMdoctitle+"",
  "width", "100%",
  "height", "100%",
  "align", "middle",
  "id", "main",
  "quality", "high",
  "bgcolor", "#ffffff",
  "name", "main",
  "allowScriptAccess","sameDomain",
  "type", "application/x-shockwave-flash",
  "pluginspage", "http://www.adobe.com/go/getflashplayer"
 );
} else if (hasRequestedVersion) {
 // if we've detected an acceptable version
 // embed the Flash Content SWF when all tests are passed
 AC_FL_RunContent(
   "src", "main",
   "width", "100%",
   "height", "100%",
   "align", "middle",
   "id", "main",
   "quality", "high",
   "bgcolor", "#ffffff",
   "name", "main",
   "allowScriptAccess","sameDomain",
   "type", "application/x-shockwave-flash",
   "pluginspage", "http://www.adobe.com/go/getflashplayer"
 );
  } else {  // flash is too old or we can't detect the plugin
    var alternateContent = 'Alternate HTML content should be placed here. '
   + 'This content requires the Adobe Flash Player. '
    + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
    document.write(alternateContent);  // insert non-flash content
  }
// -->
</script>
<noscript>
   <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
   id="main" width="100%" height="100%"
   codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
   <param name="movie" value="main.swf" />
   <param name="quality" value="high" />
   <param name="bgcolor" value="#ffffff" />
   <param name="allowScriptAccess" value="sameDomain" />
   <embed src="main.swf" quality="high" bgcolor="#ffffff"
    width="100%" height="100%" name="main" align="middle"
    play="true"
    loop="false"
    quality="high"
    allowScriptAccess="sameDomain"
    type="application/x-shockwave-flash"
    pluginspage="http://www.adobe.com/go/getflashplayer">
   </embed>
 </object>
</noscript>
</body>
</html>

 

分享到:
评论

相关推荐

    ActionScript与JavaScript相互调用

    2. **从JavaScript调用Flash** 在HTML页面中,通过JavaScript调用Flash影片中的函数,例如更改文本字段的内容。 - **HTML页面**(示例代码片段): ```html function changeText(newText) { document....

    ActionScript与JavaScript相互调用(论文)

    - **从JavaScript调用ActionScript**:允许JavaScript访问Flash影片中的对象和方法,从而实现对Flash影片的控制。 #### 3. 实现方法 - **在Flash中调用JavaScript**:可以通过`getURL()`函数来实现。该函数主要...

    ActionScript与JavaScript在教学中的相互调用.pdf

    ActionScript与JavaScript在教学中的相互调用 ActionScript是Flash中的内置编程语言,而JavaScript是网页浏览器采用的网页文本编程语言。虽然这两种编程语言不同,但是如果在教学中将二者结合起来相互调用,却可以...

    Flex与Javascript相互调用例子(附源码)

    2. **定义JavaScript调用的Flex方法**: 在Flex代码中定义一个公开方法,这个方法将被JavaScript调用。例如,你可以有一个名为`callFromJS`的方法。 3. **注册方法到JavaScript**: 使用`ExternalInterface....

    一个实现ActionScript 与JavaScript 进行相互通信的程序例子

    2. **定义可调用的ActionScript方法**:在ActionScript中定义一个公开的方法,这个方法会被JavaScript调用。例如: ```actionscript public function callFromJavaScript(param1:String):void { trace("Received ...

    javascript与flash相互调用

    2. **设置允许交互**:在Flash内容中启用JavaScript调用之前,需要确保在Flash的ActionScript设置中启用了ExternalInterface。这通常在发布设置中完成,或者在ActionScript代码中动态检查是否允许JavaScript交互。 ...

    js与as的相互调用Demo

    一、JavaScript调用ActionScript 1. Flash External Interface(外部接口) AS3引入了ExternalInterface类,允许ActionScript代码与宿主环境(如浏览器)中的JavaScript进行通信。首先,AS代码需要添加对...

    Flex与Flash相互调用实例

    通过ExternalInterface,Flash可以调用JavaScript函数,而JavaScript也可以调用Flash中的方法。 在提供的压缩包文件中,包含了两个工程目录:一个为Flash程序,另一个为Flex工程。这表明你需要分别在Flash ...

    js与as相互调用

    一、JavaScript调用ActionScript 1. ExternalInterface API:这是Flash Player提供的一个接口,允许AS与JavaScript进行双向通信。在AS中,你可以定义一个公开方法,然后通过ExternalInterface.addCallback注册,使...

    Flex和JS的相互调用,传参

    JavaScript调用Flex组件的方法则需要Flex组件提供一个可访问的接口。在Flex组件中,我们可以定义一个公共方法,并使用`ExternalInterface.addCallback`使其可以在JavaScript中调用: ```actionscript public ...

    javascript与actionscript3.0通信实例.rar

    `引入外部接口库,并调用`ExternalInterface.addCallback`方法注册一个可由JavaScript调用的函数。例如: ```actionscript import flash.external.*; ExternalInterface.addCallback("jsFunctionName", function...

    JavaScript与ActionScript3交互问题总结

    ExternalInterface API允许AS3代码暴露方法给JavaScript调用,而CDM则允许JavaScript向嵌入在页面中的Flash发送消息。 2. ExternalInterface API ExternalInterface是AS3中用于与JavaScript通信的内置类。要使用它...

    Flex ActiveX通过JS相互调用.rar

    例如,可以定义一个`flexCall`函数,当JavaScript调用它时,Flex中的业务逻辑会被执行。 4. **调用流程**: - 当Flex需要调用ActiveX方法时,会通过`ExternalInterface.call`调用预先在JavaScript中定义的接口,...

    Javascript 调用 ActionScript 的简单方法

    1. 在Flex中,ActionScript调用Javascript是比较简单的,说白了就是,在html里,怎么调用Javascript,在ActionScript就怎么调用就可以了 2. 如果用js调用as,就稍微麻烦一点,其实也比较简单 MXML代码: &lt;?xml ...

    Flex3与javascript相互交互验证

    要让JavaScript能调用Flex应用中的ActionScript方法,需要使用`ExternalInterface.addCallback`。例如,你有一个名为`callFromJS`的ActionScript方法,希望JavaScript能够调用: ```as3 ExternalInterface....

    javascript与actionscript的交互.[课件]

    它允许 ActionScript 代码直接调用 JavaScript 函数,并接收回调,反之亦然。这种方式支持 JSON 或其他数据格式的交换,使得数据共享更为方便。 - SWFObject:这是一个 JavaScript 库,用于动态插入 Flash 内容并...

    JavaScript和ActionScript的交互实现代码

    `ExternalInterface.call()` 方法允许 ActionScript 调用 JavaScript 函数,而 `ExternalInterface.addCallback()` 方法则使 JavaScript 可以调用 ActionScript 函数。这种交互机制在创建富互联网应用程序(RIA)时...

    as与js方法的相互调用

    在跨平台应用开发中,经常会遇到ActionScript (AS)与JavaScript (JS)之间的交互需求,尤其是在Flex(一种基于Adobe Flash的开发框架)的应用中。Flex是使用ActionScript编写,而网页环境通常由HTML和JavaScript控制...

Global site tag (gtag.js) - Google Analytics