简体   繁体   English

从动作脚本中调用ExtJS函数

[英]Call ExtJS functions from action script

I wonder if it is possible to call ExtJS functions from the action script? 我想知道是否可以从动作脚本中调用ExtJS函数?
For example we have the following code written on ExtJS: 例如,我们在ExtJS上编写了以下代码:

Ext.define('utils', {
    singleton : true,
    alert : function (message) {
            Ext.MessageBox.alert(Ext.locale.error, message);
    }
});  

Can it be called from within action script? 可以从动作脚本中调用吗? I know that plain java script function can be called using ExternalInterface() , but it's not suitable for me. 我知道可以使用ExternalInterface()调用普通的java脚本函数,但它不适合我。

Thanks in advance for your help! 在此先感谢您的帮助!

I don't know Extjs, but the documentation states that the Application class sets up a global variable with the name of your app. 我不知道Extjs,但是文档声明Application类设置了一个带有应用程序名称的全局变量。 If you add a public method to that class you should be able to call it from Flash using ExternalInterface (see docs ), which is the standard method of communicating between Flash and JavaScript. 如果向该类添加公共方法,则应该能够使用ExternalInterface从Flash中调用它(请参阅docs ),这是在Flash和JavaScript之间进行通信的标准方法。

Extjs: ExtJS的:

Ext.application({
    name: 'MyApp',
    launch: function() {
        Ext.create('Ext.container.Viewport', {
            items: {
                html: 'My App'
            }
        });
    },
    // Public method to receive external interface calls from Flash
    alert: function(message) {
        // Call alert method on utils
    }
});

ActionScript: 动作脚本:

ExternalInterface.call('myApp.alert', 'Hello JavaScript. Love from Flash');   

I don't know the ExternalInterface method in detail but using Ext.define you simply define a javascript object (as it is a singleton) with your given method. 我不太详细地了解ExternalInterface方法,但是使用Ext.define只需使用给定的方法定义一个javascript对象(因为它是一个单例)。 So in javascript you could simply call 所以在javascript中你可以简单地打电话

utils.alert('Hello World');

So shouldn't it be possible to use the following simple call 所以不应该使用以下简单的调用

ExternalInterface.call('utils.alert', 'Hello World');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM