Flex with Java
Aim:
To understand how to connect Flex with java from this post.
Requirements:
1). Download BlazeDS
Download BlazeDS Here
Download BlazeDS Here
2). Flash Builder
3). Jdk(above 1.5)
Download Jdk 6
Download Jdk 6
Procedure:
Step 1:
1. Open Control Panel
2. Click the System icon then a window will pop up
3. Go to the Advanced tab
4. Click the "Environment Variables"
5. Select "New" in System Variables.
6. In the Variable Name textbox type JAVA_HOME
7. In the Variable Location textbox type the JDK directory
Running Installed Sample Applications.
1. Start Tomcat by double clicking [blazeds directory]tomcat\bin\startup.bat
2. Now, check if it works by running http://localhost:8400/ in your browser.
You will get output like below
- Open [blazeds directory]tomcat\webapps\
- Copy the blazeds folder and change the name it as "yoga".
- Open "yoga" folder.
- You should be able to see 2 folders. WEB-INF and META-INF.
- Inside WEB-INF, open web.xml
Remove comment < !—begin rds and remove end rds -- >
And change to false like below
….
….
< init-param >
< param-name > useAppserverSecurity < /param-name >
< param-value > false < /param-value >
< /init-param >
….
….
6. Inside the flex folder, open remoting-config.xml and add the coding.
Note: The destination and the source values are what we'll be using in flex when we create the RemoteObject tag.
1. Create a package com.
2. Inside your Package create a HelloWorld Class. Your HelloWorld.java should look like this:
package com;
public class HelloWorld
{
public String sayHello(String name)
{
return "Hello, " + name;
}
}
3. compile the HelloWorld.java
& > javac –d . HelloWorld.java
4. you get HelloWorld.class file inside com.HelloWorld.class
Copy the package com and paste into
Open Adobe Flash builder 4
Step 1:
Open Adobe Flash Builder 4
Step 2:
Create Flex Project
Give Project name as FlexJava
Click Next and another window will open
Next and another window will open will be displayed like below
And Finish
FlexJava project will be successfully created.
And automatically FlexJava.mxml file will be created.
You give Yes
From this page, you can select Application server type as J2EE
Select Use Remote Object Access service
Select BlazeDS
Root Folder: E:\SOFTWARE\blazeds\tomcat\webapps\yoga
Root URL: http://localhost:8400/yoga
Context root: /yoga
Click Validate configuration
The web root folder and root URL are valid message will displayed on top of the window
And click ok.
Select checkbox for No Password required.
Ok.
Connect Data/services for FlexJava window will open like below
Select HelloWorld check box
And click Finish
Include following coding into the FlexJava.mxml
< ?xml version="1.0" encoding="utf-8"? >
< s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600" >
< fx:Declarations >
< mx:RemoteObject id="ro" destination="HelloWorld"/ >
< /fx:Declarations >
< mx:Panel title="java flex" height="400"
width="400" >
< mx:Canvas >
< mx:TextInput id="n" change="ro.sayHello(n.text)" x="50" y="100"/ >
< mx:Label text="{ro.sayHello.lastResult}" x="200" y="200"/ >
< /mx:Canvas >
< /mx:Panel >
< /s:Application >
Run the FlexJava.mxml
Step1:
Shutdown the Tomcat
Step 2:
Start the Tomcat
Step 3:
Run the FlexJava.mxml
Step 4: