如何将值从java脚本传递到嵌入的flex对象?

发布于 2024-10-17 23:07:48 字数 2045 浏览 3 评论 0原文

我试图弄清楚如何将字符串值(url)从 html 表单传递到嵌入的 Flex 对象。 到目前为止我发现的唯一方法是 http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_5.html 在示例中,我使用的 Flex 函数“myFunc(s:String)”注册为“ExternalInterface”,稍后从 javascript 调用

--->mySwf.mxml:

<?xml version="1.0"?>
<!-- wrapper/AddCallbackExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
  <mx:Script>
     import flash.external.*;
      import mx.controls.Alert;
     public function initApp():void {
        ExternalInterface.addCallback("myFlexFunction",myFunc);
     }  
     public function myFunc(s:String):void {

         Alert.show(s, 'Alert Box', mx.controls.Alert.OK);
     }

  </mx:Script>
  <mx:Button id="myButton" 
        label="FLEX BUTTON" 
        click="Alert.show('FLEX LOADED!', 'Alert Box', mx.controls.Alert.OK);"/>
  <mx:Label id="l1"/>

</mx:Application>

external.html

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<SCRIPT LANGUAGE="JavaScript">
    function callApp() {

        mySwf.myFlexFunction("show me something");
    }
</SCRIPT>


<form id="f1">
    <button onClick="callApp()">HTML BUTTON</button>
</form>

<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
WIDTH="850"
HEIGHT="610"
CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">
<EMBED SRC="mySwf.swf"
WIDTH="850"
HEIGHT="610"
PLAY="true" 
LOOP="true"
QUALITY="high" 
scale="noborder"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> 
</EMBED>
</OBJECT>
</html>

该方法似乎根本不起作用。如果我按下 Flex 按钮 - 我可以看到 Flex 弹出对话框。当我按下 HTML 按钮时,通过ExternalInterface 在 Flex 中调用 myFunc - 什么都没有
发生...我的代码中是否有任何错误提示? 谢谢你,

I am trying to figure how to pass string value(url) from html form to embedded flex object.
the only method i found so far is "addCallback" method described in http://livedocs.adobe.com/flex/3/html/help.html?content=passingarguments_5.html
In the example i used flex function "myFunc(s:String)" is registered with "ExternalInterface" and called later from javascript

--->mySwf.mxml:

<?xml version="1.0"?>
<!-- wrapper/AddCallbackExample.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="initApp()">
  <mx:Script>
     import flash.external.*;
      import mx.controls.Alert;
     public function initApp():void {
        ExternalInterface.addCallback("myFlexFunction",myFunc);
     }  
     public function myFunc(s:String):void {

         Alert.show(s, 'Alert Box', mx.controls.Alert.OK);
     }

  </mx:Script>
  <mx:Button id="myButton" 
        label="FLEX BUTTON" 
        click="Alert.show('FLEX LOADED!', 'Alert Box', mx.controls.Alert.OK);"/>
  <mx:Label id="l1"/>

</mx:Application>

external.html

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<SCRIPT LANGUAGE="JavaScript">
    function callApp() {

        mySwf.myFlexFunction("show me something");
    }
</SCRIPT>


<form id="f1">
    <button onClick="callApp()">HTML BUTTON</button>
</form>

<OBJECT CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
WIDTH="850"
HEIGHT="610"
CODEBASE="http://active.macromedia.com/flash5/cabs/swflash.cab#version=5,0,0,0">
<EMBED SRC="mySwf.swf"
WIDTH="850"
HEIGHT="610"
PLAY="true" 
LOOP="true"
QUALITY="high" 
scale="noborder"
PLUGINSPAGE="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash"> 
</EMBED>
</OBJECT>
</html>

The method doesn't seem to be working at all. If I push Flex button - i can see Flex popup dialog. When I push HTML button, calling myFunc in Flex via ExternalInterface - nothing
happens... Any pointers to errors in my code?
Thank you,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一花一树开 2024-10-24 23:07:48

如果您没有使用正确的浏览器,请尝试以下操作:

<SCRIPT LANGUAGE="JavaScript">
    // This function returns the appropriate reference, 
    // depending on the browser.
    function getFlexApp(appName)
    {
      if (navigator.appName.indexOf ("Microsoft") !=-1)
      {
        return window[appName];
      } 
      else 
      {
        return document[appName];
      }
    }

    function callApp() {
        getFlexApp('mySwf').myFunc("show me something");
    }

</SCRIPT>

此外,您也没有为对象提供 id(DOM 是如何识别的),

<OBJECT id='mySwf' CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">

请尝试以下操作:

ExternalInterface.addCallback("myFunc",myFunc);

Try this in case you aren't using the right browser:

<SCRIPT LANGUAGE="JavaScript">
    // This function returns the appropriate reference, 
    // depending on the browser.
    function getFlexApp(appName)
    {
      if (navigator.appName.indexOf ("Microsoft") !=-1)
      {
        return window[appName];
      } 
      else 
      {
        return document[appName];
      }
    }

    function callApp() {
        getFlexApp('mySwf').myFunc("show me something");
    }

</SCRIPT>

also you did not give an id to your object which is how the DOM identifies

<OBJECT id='mySwf' CLASSID="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000">

try this:

ExternalInterface.addCallback("myFunc",myFunc);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文