Are you running the SWF from http://localhost:8080/flex/ in your
browser? Everything seems OK to me otherwise. Try changing the my-am channel
entry to http://localhost:8080/flex/messagebroker/amf,
but you shouldn’t have needed to do it.
Matt
Hi,
I have posted a couple of messages on calling a method on a Java object using
<mx:RemoteObject> tag but so far I haven't been successful. With help
from Peter & Suresh I did proceed a little bit further but I am still
unable to successfully call the method on the server side object. Since I
described the problem in bits & pieces before, I think that I may have
missed some step(s) which I don't know about. Here is what I have done step by
step. Please let me know if I am doing anything wrong or not doing something.
Basically what I wanted to do was to verify the connectivity from the browser
side to a simple Java class on the back end using RemoteObject tag before doing
anything major. To do this I take a (String) name from a TextInput field which
is sent to the getString() method of the class called Echo which appends "Welcome
" to the incoming String & returns it back. This is displayed by the
state 'TargetState'.
1. Here is the mxml file named
SimpleRemoteObject.mxml. Please take a look at my ActionScript methods as I am
new to ActionScript as well.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns="*" layout="absolute">
<mx:TraceTarget level="0" />
<mx:Script>
<![CDATA[
import mx.rpc.events.*;
import mx.collections.*;
import mx.controls.*
private function
getNameHandler(event:ResultEvent):void
{
Result.text =
event.result.toString();
currentState='TargetState';
}
private function
faultHandler(event:FaultEvent):void
{
Alert.show(event.fault.faultstring, "Error");
Alert.show(event.fault.faultDetail, "Error");
}
]]>
</mx:Script>
<mx:states>
<mx:State
name="TargetState">
<mx:RemoveChild
child="{button1}"/>
<mx:RemoveChild
child="{formInput}"/>
<mx:RemoveChild
child="{label1}"/>
<mx:AddChild
position="lastChild">
<mx:Label x="99" y="130" width="265"
height="28" id="Result"/>
</mx:AddChild>
</mx:State>
</mx:states>
<mx:RemoteObject id="sendStringBack"
destination="EchoString" showBusyCursor="true"
fault="faultHandler(event)">
<mx:method name="getString"
result="getNameHandler(event)">
<mx:arguments>
<str>
{formInput.text}
</str>
</mx:arguments>
</mx:method>
</mx:RemoteObject>
<mx:TextInput x="119" y="129"
id="formInput"/>
<mx:Button x="119" y="170"
label="Submit" fontSize="13" id="button1"
click="sendStringBack.getString.send()"/>
<mx:Label x="119" y="86"
text="What is your name ?" width="160"
fontSize="15" id="label1"/>
</mx:Application>
For this project I defined the Flex root folder at
C:\tomcat-5.5.9\webapps\flex & flex server URL to
http://localhost:8080/flex/.
2. Defined the destination EchoString in
C:\tomcat-5.5.9\webapps\flex\WEB-INF\flex\flex-remoting-service.xml as follows,
<adapters>
<adapter-definition
id="java-object" class="flex.messaging.services.remoting.adapters.JavaAdapter"
default="true"/>
</adapters>
<default-channels>
<channel
ref="my-amf"/>
</default-channels>
<destination id="EchoString">
<properties>
<source>samples.SimpleRemoteObject.Echo</source>
</properties>
</destination>
3. Saved the mxml file in Flex Builder
which created C:\tomcat-5.5.9\webapps\flex\SimpleRemoteObject directory &
put the HTML, SWFs & _javascript_ files in it.
4. Compiled the Java class called
Echo.java & put Echo.class in
C:\tomcat-5.5.9\webapps\flex\WEB-INF\classes\samples\SimpleRemoteObject.
package samples.SimpleRemoteObject;
public class Echo {
public Echo(){
}
public String getString(String str){
System.out.println("In
Echo::getString(), got " + str);
return "Welcome " + str ;
}
}
5. Started tomcat & went to,
http://localhost:8080/flex/SimpleRemoteObject/SimpleRemoteObject.html
6. First page got painted fine, input a name & clicked on 'Submit'
7. I get Channel.Connect.Failed error. NetConnection.Call.Failed
error:HTTP:Failed in the Alert box.
C:\tomcat-5.5.9\webapps\flex\WEB-INF\flex\flex-enterprise-services.xml
has,
<channel-definition
id="my-amf" class="mx.messaging.channels.AMFChannel">
<endpoint
uri="http://{server.name}:{server.port}/{context.root}/messagebroker/amf"
class="flex.messaging.endpoints.AMFEndpoint"/>
<properties>
<polling-enabled>false</polling-enabled>
</properties>
</channel-definition>
Thanks,
Aejaz
--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com
SPONSORED LINKS
YAHOO! GROUPS LINKS