如何将 Java 方法调用到 Adobe Flex 移动应用程序中
我想学习 Adobe Flex 移动开发。
我创建了一个名为 SampleProject
的新项目,然后在默认包中获得了 SampleProject.mxml
和 SampleProjectHomeView.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
中的上述类调用 add
和 sub
方法?
请任何人帮助我。
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以使用 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.