从 javascript 调用 as3 函数时出现问题

发布于 2024-11-07 12:04:09 字数 6986 浏览 3 评论 0原文

我团队的项目有一个嵌入 JavaScript 的 swf,我们实际上使用 java servlet 来创建 html/JavaScript。我正在尝试使用as3的ExternalInterface添加一个回调,该回调将在javascript中调用,但我尝试过的所有方法都不起作用。

以下是一些相关代码:

Javascript:(记住使用 servlet,这就是为什么这一切都在字符串内)

<html>
<head>
    <script src='/oddmanor/AC_OETags.js' language='javascript'></script>
    <script language='JavaScript' type='text/javascript'>
        var requiredMajorVersion = 10;
        var requiredMinorVersion = 1;
        var requiredRevision = 0;
    </script>
</head>
<body marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>
    <script language='JavaScript' type='text/javascript'>
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (hasReqestedVersion) {
        AC_FL_RunContent(
            'src', 'http://localhost:8080/download/FlashClient',
            'width', '760',
            'height', '600',
            'align', 'middle',
            'id', 'myswf',
            'quality', 'high',
            'bgcolor', '#FFFFFF',
            'name', 'myswf',
            'allowScriptAccess','always',
            'type', 'application/x-shockwave-flash',
            'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
            'pluginspage', 'http://www.adobe.com/go/getflashplayer',
            'wmode', 'opaque',
            'flashvars', 'challenge=c0oC5CjXjOpRagA0Eh0xi2uYCv-8HZfz-XpG2CCmJHZMnFQK8wYI4kultTUGYGff3N8-5lco_TrR2MfCvnUhVUyCOII6Xtem2rRIPD3SBJ18YxUSkH2GykI78Im2pfqw-UR44OqlOuZGafL3VRkn7KSiMm-AWbZt60MFHzHFaeEhIQke9aj04UkmaJL1MWoOU4CklVxoqX-ag146KilHEroL46JxcD9TLvCW9MG_Gv9fTAYOZK2_FEsHUMg0kP8WjyheWBftNxOuZoHQ9bIsB9EDe9pR4RwZryCjyL6p4T7Si0dMFfmEvml5mkhRYG74yj7pLDKTgHJeURUKOYY9RU9mFbsA82Q8-7cXeGlvQnk'
        );
    } else {
        var alternateContent = 'Alternate HTML content should be placed here.<BR>'
        + 'This content requires the Adobe Flash Player. '
        + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
        document.write(alternateContent);
    }

    </script>
    <noscript>
    <div align="middle" id="swf">
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
    <param name="src" value="http://localhost:8080/download/FlashClient">
    <param name="width" value="760">
    <param name="height" value="600">
    <param name="align" value="middle">
    <param name="id" value="myswf">
    <param name="quality" value="high">
    <param name="bgcolor" value="#FFFFFF">
    <param name="name" value="myswf">
    <param name="allowScriptAccess" value="always">
    <param name="type" value="application/x-shockwave-flash">
    <param name="codebase" value="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
    <param name="pluginspage" value="http://www.adobe.com/go/getflashplayer">
    <param name="wmode" value="opaque">
    <param name="flashvars" value="challenge=c0oC5CjXjOpRagA0Eh0xi2uYCv-8HZfz-XpG2CCmJHZMnFQK8wYI4kultTUGYGff3N8-5lco_TrR2MfCvnUhVUyCOII6Xtem2rRIPD3SBJ18YxUSkH2GykI78Im2pfqw-UR44OqlOuZGafL3VRkn7KSiMm-AWbZt60MFHzHFaeEhIQke9aj04UkmaJL1MWoOU4CklVxoqX-ag146KilHEroL46JxcD9TLvCW9MG_Gv9fTAYOZK2_FEsHUMg0kP8WjyheWBftNxOuZoHQ9bIsB9EDe9pR4RwZryCjyL6p4T7Si0dMFfmEvml5mkhRYG74yj7pLDKTgHJeURUKOYY9RU9mFbsA82Q8-7cXeGlvQnk">
    <embed src="http://localhost:8080/download/FlashClient" width="760" height="600" align="middle" id="myswf" quality="high" bgcolor="#FFFFFF" name="myswf" allowScriptAccess="always" type="application/x-shockwave-flash" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="opaque" flashvars="challenge=c0oC5CjXjOpRagA0Eh0xi2uYCv-8HZfz-XpG2CCmJHZMnFQK8wYI4kultTUGYGff3N8-5lco_TrR2MfCvnUhVUyCOII6Xtem2rRIPD3SBJ18YxUSkH2GykI78Im2pfqw-UR44OqlOuZGafL3VRkn7KSiMm-AWbZt60MFHzHFaeEhIQke9aj04UkmaJL1MWoOU4CklVxoqX-ag146KilHEroL46JxcD9TLvCW9MG_Gv9fTAYOZK2_FEsHUMg0kP8WjyheWBftNxOuZoHQ9bIsB9EDe9pR4RwZryCjyL6p4T7Si0dMFfmEvml5mkhRYG74yj7pLDKTgHJeURUKOYY9RU9mFbsA82Q8-7cXeGlvQnk" />
    </object>
        This content requires the Adobe Flash Player and a browser with JavaScript enabled.
        <a href='http://www.adobe.com/go/getflash/'>Get Flash</a>
    </div>
    </noscript>
    <div>
        <a href='http://d1fjc9whyjwawe.cloudfront.net/KingX_Studios_Terms_of_Service.pdf' TARGET='_blank'>KingX Terms of Service</a> | 
        <a href='http://d1fjc9whyjwawe.cloudfront.net/Privacy_Policy_Odd_Manor.pdf' TARGET='_blank'>Privacy Policy</a> | 
        <a href='http://www.activeboard.com/forum.spark?aBID=138536&topicID=42164567&p=3' TARGET='_blank'>Report a Bug</a>
    </div>
    <div id='fb-root'></div>
    <script src='http://connect.facebook.net/en_US/all.js'></script>
    <script type='text/javascript'>
        FB.init(
            {
                'appId': '191461020878253',
                'status': true,
                'cookie': true,
                'channelUrl': 'http://nimbus.com:8080/oddmanor/fb_channel.html'
            }
        );

        var callback = function(data) {
            var res;
            if (data['order_id']) {
                res = true;
            }
            else {
                res = false;
            }
            var me;
            if (navigator.appName.indexOf('Microsoft') != -1) {
                me = window['myswf'];
            }
            else {
                me = document['myswf'];
            }
            me.onPurchaseCompletion(res);
        };

        function getFlashMovie(movieName) {
           var isIE = navigator.appName.indexOf("Microsoft") != -1;
           return (isIE) ? window[movieName] : document[movieName];  }

        function getFriendsUsingApp() 
        {
            alert("ALERRRRRT!!!");
            getFlashMovie("myswf").passFriendArrayToFlash();
            return "set2";
        }

        function makePurchase(objectInfo) {
            var obj = {
                'method': 'pay',
                'order_info': objectInfo,
                'purchase_type': 'item'
            };

            FB.ui(obj, callback);
        }
    </script>
</body>
</html>



另外,我还删除了一些与这个问题没有任何关系的 JavaScript 代码(希望如此),所以如果缺少标签或其他内容可能不是我的问题。

注意我正确地嵌入了这个并进入swf,允许它调用javascript函数(as3调用getStuff fn),使用ExternalInterface,它可以工作,但JS->as3不起作用='(。

其他注释, FlashClient swf 的名称...

我无法将电影对象用于任何用途(getFlashMovie 的返回值),如果我在工作后尝试不使用任何代码...

动作脚本代码正确调用外部接口 addCallback 函数(在 try catch 中调用,这就是我所知道的) if(外部...可用) 外部...addCallback("passStuff", as3PassStuff)

我唯一能想到的; 1)嵌入代码没有正确创建对象,因为我不能将电影用于任何用途 2) 我的 swf 创建方式很奇怪,并且不允许脚本访问。

我们使用 FlashBuilder 来构建 swf。

So my team's project has an swf embedded in JavaScript, we're actually using java servlet's to create the html/JavaScript. I am attempting to use as3's ExternalInterface to add a callback which would get called in the javascript but everything I have tried will not work.

Here is some of the related code:

Javascript:(remember using servlets thats why this is all inside a string)

<html>
<head>
    <script src='/oddmanor/AC_OETags.js' language='javascript'></script>
    <script language='JavaScript' type='text/javascript'>
        var requiredMajorVersion = 10;
        var requiredMinorVersion = 1;
        var requiredRevision = 0;
    </script>
</head>
<body marginwidth='0' marginheight='0' leftmargin='0' topmargin='0'>
    <script language='JavaScript' type='text/javascript'>
    var hasReqestedVersion = DetectFlashVer(requiredMajorVersion, requiredMinorVersion, requiredRevision);
    if (hasReqestedVersion) {
        AC_FL_RunContent(
            'src', 'http://localhost:8080/download/FlashClient',
            'width', '760',
            'height', '600',
            'align', 'middle',
            'id', 'myswf',
            'quality', 'high',
            'bgcolor', '#FFFFFF',
            'name', 'myswf',
            'allowScriptAccess','always',
            'type', 'application/x-shockwave-flash',
            'codebase', 'http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab',
            'pluginspage', 'http://www.adobe.com/go/getflashplayer',
            'wmode', 'opaque',
            'flashvars', 'challenge=c0oC5CjXjOpRagA0Eh0xi2uYCv-8HZfz-XpG2CCmJHZMnFQK8wYI4kultTUGYGff3N8-5lco_TrR2MfCvnUhVUyCOII6Xtem2rRIPD3SBJ18YxUSkH2GykI78Im2pfqw-UR44OqlOuZGafL3VRkn7KSiMm-AWbZt60MFHzHFaeEhIQke9aj04UkmaJL1MWoOU4CklVxoqX-ag146KilHEroL46JxcD9TLvCW9MG_Gv9fTAYOZK2_FEsHUMg0kP8WjyheWBftNxOuZoHQ9bIsB9EDe9pR4RwZryCjyL6p4T7Si0dMFfmEvml5mkhRYG74yj7pLDKTgHJeURUKOYY9RU9mFbsA82Q8-7cXeGlvQnk'
        );
    } else {
        var alternateContent = 'Alternate HTML content should be placed here.<BR>'
        + 'This content requires the Adobe Flash Player. '
        + '<a href=http://www.adobe.com/go/getflash/>Get Flash</a>';
        document.write(alternateContent);
    }

    </script>
    <noscript>
    <div align="middle" id="swf">
    <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
    <param name="src" value="http://localhost:8080/download/FlashClient">
    <param name="width" value="760">
    <param name="height" value="600">
    <param name="align" value="middle">
    <param name="id" value="myswf">
    <param name="quality" value="high">
    <param name="bgcolor" value="#FFFFFF">
    <param name="name" value="myswf">
    <param name="allowScriptAccess" value="always">
    <param name="type" value="application/x-shockwave-flash">
    <param name="codebase" value="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab">
    <param name="pluginspage" value="http://www.adobe.com/go/getflashplayer">
    <param name="wmode" value="opaque">
    <param name="flashvars" value="challenge=c0oC5CjXjOpRagA0Eh0xi2uYCv-8HZfz-XpG2CCmJHZMnFQK8wYI4kultTUGYGff3N8-5lco_TrR2MfCvnUhVUyCOII6Xtem2rRIPD3SBJ18YxUSkH2GykI78Im2pfqw-UR44OqlOuZGafL3VRkn7KSiMm-AWbZt60MFHzHFaeEhIQke9aj04UkmaJL1MWoOU4CklVxoqX-ag146KilHEroL46JxcD9TLvCW9MG_Gv9fTAYOZK2_FEsHUMg0kP8WjyheWBftNxOuZoHQ9bIsB9EDe9pR4RwZryCjyL6p4T7Si0dMFfmEvml5mkhRYG74yj7pLDKTgHJeURUKOYY9RU9mFbsA82Q8-7cXeGlvQnk">
    <embed src="http://localhost:8080/download/FlashClient" width="760" height="600" align="middle" id="myswf" quality="high" bgcolor="#FFFFFF" name="myswf" allowScriptAccess="always" type="application/x-shockwave-flash" codebase="http://fpdownload.macromedia.com/get/flashplayer/current/swflash.cab" pluginspage="http://www.macromedia.com/go/getflashplayer" wmode="opaque" flashvars="challenge=c0oC5CjXjOpRagA0Eh0xi2uYCv-8HZfz-XpG2CCmJHZMnFQK8wYI4kultTUGYGff3N8-5lco_TrR2MfCvnUhVUyCOII6Xtem2rRIPD3SBJ18YxUSkH2GykI78Im2pfqw-UR44OqlOuZGafL3VRkn7KSiMm-AWbZt60MFHzHFaeEhIQke9aj04UkmaJL1MWoOU4CklVxoqX-ag146KilHEroL46JxcD9TLvCW9MG_Gv9fTAYOZK2_FEsHUMg0kP8WjyheWBftNxOuZoHQ9bIsB9EDe9pR4RwZryCjyL6p4T7Si0dMFfmEvml5mkhRYG74yj7pLDKTgHJeURUKOYY9RU9mFbsA82Q8-7cXeGlvQnk" />
    </object>
        This content requires the Adobe Flash Player and a browser with JavaScript enabled.
        <a href='http://www.adobe.com/go/getflash/'>Get Flash</a>
    </div>
    </noscript>
    <div>
        <a href='http://d1fjc9whyjwawe.cloudfront.net/KingX_Studios_Terms_of_Service.pdf' TARGET='_blank'>KingX Terms of Service</a> | 
        <a href='http://d1fjc9whyjwawe.cloudfront.net/Privacy_Policy_Odd_Manor.pdf' TARGET='_blank'>Privacy Policy</a> | 
        <a href='http://www.activeboard.com/forum.spark?aBID=138536&topicID=42164567&p=3' TARGET='_blank'>Report a Bug</a>
    </div>
    <div id='fb-root'></div>
    <script src='http://connect.facebook.net/en_US/all.js'></script>
    <script type='text/javascript'>
        FB.init(
            {
                'appId': '191461020878253',
                'status': true,
                'cookie': true,
                'channelUrl': 'http://nimbus.com:8080/oddmanor/fb_channel.html'
            }
        );

        var callback = function(data) {
            var res;
            if (data['order_id']) {
                res = true;
            }
            else {
                res = false;
            }
            var me;
            if (navigator.appName.indexOf('Microsoft') != -1) {
                me = window['myswf'];
            }
            else {
                me = document['myswf'];
            }
            me.onPurchaseCompletion(res);
        };

        function getFlashMovie(movieName) {
           var isIE = navigator.appName.indexOf("Microsoft") != -1;
           return (isIE) ? window[movieName] : document[movieName];  }

        function getFriendsUsingApp() 
        {
            alert("ALERRRRRT!!!");
            getFlashMovie("myswf").passFriendArrayToFlash();
            return "set2";
        }

        function makePurchase(objectInfo) {
            var obj = {
                'method': 'pay',
                'order_info': objectInfo,
                'purchase_type': 'item'
            };

            FB.ui(obj, callback);
        }
    </script>
</body>
</html>

Also I ripped out a bit of JavaScript code that didnt have anything to do with this problem(hopefully) so if there is a missing tag or something that's probably not my problem.

NOTE I embed this correctly and get into the swf allowing it to call javascript functions(as3 calls the getStuff fn), using the ExternalInterface, which works but JS->as3 does NOT work ='(.

Other notes,
FlashClient is the name of the swf....

I cant use the movie object for anything (the return value of getFlashMovie), if I try to use no code after works...

The action script code calls the external interface addCallback function correctly(called in a try catch that's how I know)
if(External...Availible)
External...addCallback("passStuff", as3PassStuff)

The only things I can think of;
1) The embed code isnt creating the object correctly, since I cant use the movie for anything
2) my swf is being created weird and doesnt allow script access.

We are using FlashBuilder to build the swf.

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

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

发布评论

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

评论(1

肥爪爪 2024-11-14 12:04:09
System.security.allowDomain("*");

在我的 swf 中,我们很好。

System.security.allowDomain("*");

in my swf and we're good.

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