「java调用flex」java调用flash

博主:adminadmin 2023-01-24 17:15:08 379

今天给各位分享java调用flex的知识,其中也会对java调用flash进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

Java 和 flex 怎么交互?

你做项目的时候难道是就起一个工程吗?这样不规范啊,你应该是有好多个java application的工程,然后有一个web application的工程,还有一个flex的工程。最后用ant把java application的工程都打成jar包放到web application的/WEB-INFO/lib下,flex工程编译好的东西放到webRoot下。这样不就搞定了。最后你再用ant打个war包就好了。

Flex4.5 怎么才能调试java代码

一种比较简单的方法是使用WebService与java连。

我做过这样的project,后台是axis+spring+hibernate。

至于flex如何调用web service,你可以查看flex builder中帮助文档,里面有比较详细的例子。注意flex调用都是异步的

答复修改:

开发java代码可以在eclipse上面啊,为什么在flex builder上面?

java axis开发好web service后,部署到tomcat中,然后由flex来调用

FLEX有直接调用JAVA的方法吗

推荐用remoteObject方式。

这里需要用到services-config.xml配置文件,我个人理解的该配置文件就是一个Flex与业务层间的通道。

假设业务层有一个java类TestAction.java

①那么services-config.xml配置文件中的写法就是这样:

destination id="TestAction"

channels

channel ref="spring-amf" /

/channels

/destination

完成这个配置之后就可以在Flex层调用TestAction里的方法了。

②在MXML文件中这样写:

mx:RemoteObject id="TestAction"

destination="TestAction"

showBusyCursor="true"

mx:method name="findDataList"

result="processFindDataList(event.result)"

/mx:method

/mx:RemoteObject

其中destination就是你在services-config.xml配置文件声明的通道,

id是你在对应的AS文件可以用的名字。id你可以用随便的名字,你id起的是什么名字那你在AS文件中就用什么名字。

③AS文件中这样写

private function getDataList():void

{

TestAction.findDataList(String para1,String para2,.....)

}

findDataList是TestAction中声明的方法。TestAction.findDataList返回的结果用processFindDataList方法接收(在mx:RemoteObject 中已经声明)

private function processFindDataList(result:Object):void

{

if(result != null)

{

处理;

}

else

{

Alert.show("没有你想要的结果");

}

}

flex 调用java 构造函数

// var ro:RemoteObject = new RemoteObject();

// ro.destination = "helloJavaFlex";

// ro.helloJavaFlex("mark");

// ro.addEventListener(ResultEvent.RESULT,onGetDataSuccess);//成功

// ro.addEventListener(FaultEvent.FAULT,onFault);//失败

采用blazeds

部分代码片段

flex调用Java方法连接sqlserver

基于blazeDS的flex4与spring的程序实例步骤

环境:

jdk1.6

j2ee1.5

spring2.5.6

blazeDS3.3

tomcat6.0

flex4

myeclipse8.5

flashBuilder4

步骤:

一、 启动好blazeDS(即启动tomcat,在[tomcat]/webapps目录下产生一个blazeds文件夹(三个war包产生一个blazeds文件夹));

在myeclipse8.5新建一个web Project工程,工程名为webSpring;

把此工程加入blazeDS支持(即用blazeds下的WEB-INF文件夹替换掉web工程下的WEB-INF文件夹);

加入spring支持(把spring相关的jar包拷贝到webSpring/WebRoot/WEB-INF/lib目录下即可)。

二、 1. 在javaWeb工程webSpring的str目录下分别新建一下两个包:

cn.xuediit.myFactory、cn.xuediit.myService;

2. 在cn.xuediit.myFctory包下新建两个类:FlexFactoryImpl.java和SpringFactoryInstance.java

(1). FlexFactoryImpl.java:

package cn.xuediit.myFactory;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import flex.messaging.FactoryInstance;

import flex.messaging.FlexFactory;

import flex.messaging.config.ConfigMap;

public class FlexFactoryImpl implements FlexFactory {

private Log log = LogFactory.getLog(getClass());

/*override interface method*/

public void initialize(String id, ConfigMap configMap) {

System.out.println("1---flex工厂实现类重写的方法initialize");

}

/*override interface method*/

public FactoryInstance createFactoryInstance(String id, ConfigMap properties) {

System.out.println("2---flex工厂实现类重写的方法createFactoryInstance");

log.info("Create FactoryInstance.");

SpringFactoryInstance instance = new SpringFactoryInstance(this, id, properties);

instance.setSource(properties.getPropertyAsString(SOURCE, instance.getId()));

return instance;

}

/*override interface method*/

public Object lookup(FactoryInstance instanceInfo) {

System.out.println("4---flex工厂实现类重写的方法lookup");

log.info("Lookup service object.");

return instanceInfo.lookup();

}

}

(2).SpringFactoryInstance.java

package cn.xuediit.myFactory;

import org.apache.commons.logging.Log;

import org.apache.commons.logging.LogFactory;

import org.springframework.beans.BeansException;

import org.springframework.beans.factory.NoSuchBeanDefinitionException;

import org.springframework.context.ApplicationContext;

import org.springframework.web.context.support.WebApplicationContextUtils;

import flex.messaging.FactoryInstance;

import flex.messaging.FlexContext;

import flex.messaging.FlexFactory;

import flex.messaging.config.ConfigMap;

import flex.messaging.services.ServiceException;

public class SpringFactoryInstance extends FactoryInstance {

private Log log = LogFactory.getLog(getClass());

SpringFactoryInstance(FlexFactory factory, String id, ConfigMap properties) {

super(factory, id, properties);

}

public Object lookup() {

System.out.println("3---spring工厂类的方法lookup");

ApplicationContext appContext = WebApplicationContextUtils.getRequiredWebApplicationContext(FlexContext.getServletConfig().getServletContext());

String beanName = getSource();

try {

log.info("Lookup bean from Spring ApplicationContext: " + beanName);

return appContext.getBean(beanName);

} catch (NoSuchBeanDefinitionException nex) {

ServiceException e = new ServiceException();

String msg = "Spring service named '" + beanName + "' does not exist.";

e.setMessage(msg);

e.setRootCause(nex);

e.setDetails(msg);

e.setCode("Server.Processing");

throw e;

} catch (BeansException bex) {

ServiceException e = new ServiceException();

String msg = "Unable to create Spring service named '" + beanName + "'.";

e.setMessage(msg);

e.setRootCause(bex);

e.setDetails(msg);

e.setCode("Server.Processing");

throw e;

} catch (Exception ex) {

ServiceException e = new ServiceException();

String msg = "Unexpected exception when trying to create Spring service named '" + beanName + "'.";

e.setMessage(msg);

e.setRootCause(ex);

e.setDetails(msg);

e.setCode("Server.Processing");

throw e;

}

}

}

3. 在cn.xuediit.myService包下新建两个类:FService.java和FServicesImpl.java

(1). FService.java

package cn.xuediit.myService;

public interface FService {

public String sayHello(String name);

}

(2). FServicesImpl.java

package cn.xuediit.myService;

public class FServicesImpl implements FService {

public String sayHello(String name) {

System.out.println("5---服务层实现类(本质上的与flex交互的类)");

return "我是服务层的服务实现类==" + name;

}

}

三、 1、 在javaWeb工程webSpring下,在文件webSpring/WebRoot/WEB-INF/web.xml的web-app标签下添加子节点:

listener

listener-class

org.springframework.web.context.ContextLoaderListener

/listener-class

/listener

2、 在javaWeb工程webSpring下,在webSpring/WebRoot/WEB-INF目录下新建一个文件:applicationContext.xml

?xml version="1.0" encoding="UTF-8"?

beans xmlns=""

xmlns:xsi=""

xmlns:tx=""

xsi:schemaLocation="

"

bean id="fServiceImplBeanID" class="cn.xuediit.myService.FServicesImpl"/bean

/beans

四、 1、 在javaWeb工程webSpring下,在WebRoot/WEB-INF/flex/remoting-config.xml文件中的service标签下添加:

destination id="destinationID"

properties

factoryflexFactoryImplID/factory

sourcefServiceImplBeanID/source

scopeapplication/scope

/properties

/destination

2、 在javaWeb工程webSpring下,在WebRoot/WEB-INF/flex/services-config.xml文件中的services-config标签下添加:

factories

factory id="flexFactoryImplID" class="cn.xuediit.myFactory.FlexFactoryImpl"/

/factories

五、 给此javaWeb工程添加tomcat支持,启动tomcat(这个容易就不说了)。

六、 在flashBuilder下新建一个基于blazeDS的flex项目(以webSpring为后台工程),工程名为webFb;

webFb.mxml:

?xml version="1.0" encoding="utf-8"?

s:Application xmlns:fx=""

xmlns:s="library://ns.adobe.com/flex/spark"

xmlns:mx="library://ns.adobe.com/flex/halo"

minWidth="500" minHeight="200"

fx:Script

![CDATA[

import mx.core.Application;

import mx.rpc.events.FaultEvent;

import mx.collections.ArrayCollection;

import mx.rpc.remoting.mxml.RemoteObject;

import mx.controls.Alert;

import mx.rpc.events.ResultEvent;

public function submit(name:String):void{

var remote:RemoteObject = new RemoteObject();

remote.destination = "destinationID";

remote.endpoint = "";

remote.addEventListener(ResultEvent.RESULT, myResult);

remote.addEventListener(FaultEvent.FAULT,fault);

remote.sayHello(name);

}

private function myResult(evt:ResultEvent):void{

Alert.show(evt.result.toString());

}

private function fault(evt:FaultEvent):void{

Alert.show(evt.fault.message);

}

]]

/fx:Script

s:Button x="240" y="11" label="要发送到" click="submit(nameTxt.text)"/

s:Label x="16" y="11" text="姓名"/

s:TextInput id="nameTxt" x="100" y="100"/

/s:Application

java编程,flex是什么东西

简单的说一下,flex之所以出现,是应为编写flash对于编程人员来说太hard了,编写flash要用美术功底,还要一帧一帧的弄,对程序员来说太难,所以flex应运出世。flex就是以编程(程序员熟悉)的方式来实现flash功能,所用语言为actionscript语言,最后会编译出一个swf文件,也就是flash文件,这样对程序员来说就方便多了。听同事说google地图(网页)好像就是用flex做的。

java调用flex的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java调用flash、java调用flex的信息别忘了在本站进行查找喔。