prasad.gai
prasad.gai

Reputation: 2987

How to call a Java method into an Adobe Flex mobile application

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.

Upvotes: 2

Views: 1259

Answers (1)

wyz
wyz

Reputation: 761

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.

Upvotes: 1

Related Questions