如何将 Java 方法调用到 Adob​​e Flex 移动应用程序中

发布于 2024-12-17 13:03:20 字数 1112 浏览 1 评论 0原文

我想学习 Adob​​e Flex 移动开发。

我创建了一个名为 SampleProject 的新项目,然后在默认包中获得了 SampleProject.mxmlSampleProjectHomeView.mxml

我使用了脚本标签来实现如下:

 <?xml version="1.0" encoding="utf-8"?>
 <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[

              // here I would like to call methods from java class      

    ]]>
</fx:Script>

从上面的代码中,我想在脚本中调用 Java 类的方法。我编写的 Java 代码如下:

   public class Sample 
  {

public void add(int a,int b)
{

    int c;

    c=a+b;

    System.out.println("addition of two"+c);

}

public void sub(int a,int b)
{

    int c;

    c=a+b;

    System.out.println("subtraction of two"+c);

}

}

如何从 SampleProjectHomeView.mxml 中的上述类调用 addsub 方法?

请任何人帮助我。

I would like to learn Adobe Flex mobile development.

I have created a new project called SampleProject, then I got SampleProject.mxml in default package and SampleProjectHomeView.mxml.

I have used a script tag for implementation as follows:

 <?xml version="1.0" encoding="utf-8"?>
 <s:View xmlns:fx="http://ns.adobe.com/mxml/2009" 
    xmlns:s="library://ns.adobe.com/flex/spark" title="HomeView">
<fx:Declarations>
    <!-- Place non-visual elements (e.g., services, value objects) here -->
</fx:Declarations>

<fx:Script>
    <![CDATA[

              // here I would like to call methods from java class      

    ]]>
</fx:Script>

From the code above I would like to call methods from a Java class in script. I have written the Java code as follows:

   public class Sample 
  {

public void add(int a,int b)
{

    int c;

    c=a+b;

    System.out.println("addition of two"+c);

}

public void sub(int a,int b)
{

    int c;

    c=a+b;

    System.out.println("subtraction of two"+c);

}

}

How can I call the add and sub methods from the class above in SampleProjectHomeView.mxml?

Please, anybody, help me.

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

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

发布评论

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

评论(1

泼猴你往哪里跑 2024-12-24 13:03:20

您可以使用 BlazeDS 使 Flex 应用程序与 Java 应用程序对话。 http://opensource.adobe.com/wiki/display/blazeds/BlazeDS 。通常人们使用Spring-Flex(http://www.springsource.org/spring-flex)进行集成。

我之前已经这样做过,并且需要大量的集成工作,特别是如果您想自动化整个构建过程。也许现在更容易了,但我真的不建议您走这条路,除非您对 Java 代码进行了大量投资。

另一种替代方法是创建一个简单的 RESTful Web 服务(建议使用 play-framework)并让 Flex 与该 Web 服务对话。毕竟,这归结为您的技术决策的权衡。

You can make your Flex application talk to a Java application using BlazeDS. http://opensource.adobe.com/wiki/display/blazeds/BlazeDS. And usually people use Spring-Flex (http://www.springsource.org/spring-flex) for integration.

I have done this before and there is a lot of integration effort, especially if you want to automate the whole build process. Maybe it is much easier now, but I do not really recommend you go this route unless you have significant investment in your Java code.

Another alternative approach is create a simple RESTful webservice (play-framework is recommended) and let Flex talk to the web-service. After all it boils down to the trade-off of your technology decision.

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