Flex 连数据库

原创 2007年10月12日 12:23:00

连接数据库1:

import DataService.DsQiLogin;
  
 private var objDsQiLogin:DsQiLogin;

import com.iir.qi.query.*;

private function Init():void{
   
   cfg.addEventListener("ConfigResult",configResult);
   cfg.getConfig();
   objAreaFlag.flag = false;
  }
  
  private function configResult(event:Event):void{
   qiAddress=cfg.QiAddress;
   qiService=cfg.QiService;
   qiProcess=cfg.QiProcess;
   qiPort=cfg.QiPort;
   init();
   //preInit();
  }
  
  private function init():void{     
    objDsQiLogin = new DsQiLogin("msoerries", "catfish", "inFlowTestingApp",loginResult,loginException);
   }
  
  private function loginResult(event:Event):void{
   this.qiSession = objDsQiLogin.qiSession;
  }
  
  private function loginException(event:Event):void{
   Alert.show("Error About Connection~!"); 
  } 

连数据库2:

private function preInit():void{
   cfg.addEventListener("ConfigResult",configResult);
   cfg.getConfig();
  }
  
  private function configResult(event:Event):void{
   qiAddress=cfg.QiAddress;
   qiService=cfg.QiService;
   qiProcess=cfg.QiProcess;
   qiPort=cfg.QiPort;
   init();
   
  }
  
  private function init():void{
   qiLogin.setService(qiService);
   qiLogin.setProcess(qiProcess);
   qiLogin.login("msoerries", "catfish", "inFlowTestingApp");
  }

private function qiLoginResponse():void{
   qiSession = qiLogin.getResponse().toString(); 
  }
  
  private function qiLoginException():void{
   Alert.show(qiLogin.getResponse().toString());
  }

<qi:QiAgent id="qiLogin" qiAgentAddress="{qiAddress}" qiAgentPort="{qiPort}" qiResponse="qiLoginResponse()" qiException="qiLoginException()"/>

config:

package
{

 import mx.rpc.http.HTTPService;
 import mx.rpc.events.ResultEvent;
 import mx.controls.Alert;
 import mx.collections.ArrayCollection;
 import mx.rpc.events.FaultEvent;
 import flash.events.Event
 import flash.events.EventDispatcher;
 import com.iir.qi.QiAgent;
 
 [Event(name="ConfigResult", type="flash.events.Events")]
 
 [Bindable]
 public class qiConfig extends EventDispatcher
 {
  
  private static var _instance:qiConfig;
  
  private var configRequest:HTTPService = new HTTPService();
  

  private var _qiAddress:String;
  private var _qiService:String;
  private var _qiPort:String;
  private var _qiProcess:String
  
  
  private var configData:ArrayCollection = new ArrayCollection();
  
  public function qiConfig(enforcer:SingletonEnforcer) {}
  
  public static function getInstance():qiConfig
  {
   if(qiConfig._instance == null)
   {
    qiConfig._instance = new qiConfig(new SingletonEnforcer);
   }
   return qiConfig._instance;
  }
  
  public function get QiAddress():String { return _qiAddress; }
  public function set QiAddress(value:String):void { _qiAddress = value; }
  
  public function get QiService():String { return _qiService; }
  public function set QiService(value:String):void {_qiService = value; }
  
  public function get QiPort():String { return _qiPort; }
  public function set QiPort(value:String):void { _qiPort = value; }
  
  public function get QiProcess():String { return _qiProcess; }
  public function set QiProcess(value:String):void {_qiProcess = value; }
  
  public function getConfig():void
  {
   configRequest.url = "Config/Config.xml";
   configRequest.addEventListener(ResultEvent.RESULT, configResult);
   configRequest.addEventListener(FaultEvent.FAULT, configFault);
   configRequest.send();
  }
  
  private function configResult(event:ResultEvent):void
  {
   //Alert.show("got result");
   configData = configRequest.lastResult.config.qiConfig;
   //Alert.show(configData.getItemAt(0).qiAddress);
   QiAddress = configData.getItemAt(0).qiAddress;
   QiService = configData.getItemAt(0).qiService;
   QiPort = configData.getItemAt(0).qiPort;
   QiProcess = configData.getItemAt(0).qiProcess;
   //var dspEvnt:EventDispatcher = new EventDispatcher();
   //dspEvnt.dispatchEvent(new Event("ConfigResult"));
   dispatchEvent(new Event("ConfigResult"));
   //Alert.show("Dispatched Event");
  }
  
  private function configFault(event:FaultEvent):void
  {
   Alert.show("Error Retrieving Configuration file");
  }
  
  public function QiAgentFactory():QiAgent
  {
   var agent:QiAgent = new QiAgent();
   agent.setAgentAddress(_qiAddress);
   agent.setProcess(_qiProcess);
   agent.setAgentPort(_qiPort);
   agent.setService(_qiService);
   return agent;
  }
 }
]

cofig _xml:

datalogin:

package DataService
{
 import flash.events.EventDispatcher;
 import com.iir.qi.QiAgent;
 import com.iir.qi.QiEvent;
 import mx.controls.Alert;
 import flash.events.Event;
 
 [Event(name="LoginResult", type="flash.events.Events")]
 [Event(name="LoginException", type="flash.events.Events")]
 

 public class DsQiLogin extends EventDispatcher
 {
  public var qiLogin:QiAgent;
 
  public var qiSession:String;
  
  public function DsQiLogin(userName:String, passWord:String, appHandle:String, loginListener:Function, exceptionListener:Function):void
  {
   qiLogin = qiConfig.getInstance().QiAgentFactory();
   qiLogin.addEventListener("qiResponse", qiLoginResult);
   qiLogin.addEventListener("qiException", qiLoginException);
   if (loginListener != null)
   {
    addEventListener("LoginResult", loginListener);
   }
   if (exceptionListener != null)
   {
    addEventListener("LoginException", exceptionListener);
   }
   qiLogin.login(userName, passWord, appHandle);
  }
  
  private function qiLoginResult(event:QiEvent):void
  {
   qiSession = qiLogin.getResponse().toString();
   dispatchEvent(new Event("LoginResult"));
  }
  
  private function qiLoginException(event:QiEvent):void
  {
   Alert.show(event.getResponse().toString());
   dispatchEvent(new Event("LoginExeption"));
  }
 }
}

Flex连接数据库三种方法

首先,做一点说明。Flex是不能直接连接数据库的,这一点大家需要知道,它只能间接地连接数据库。Flex中提供了三种方式:HttpService,WebService 和RemoteObject。其中H...
  • xiaosong2007
  • xiaosong2007
  • 2009-03-08 20:13:00
  • 12843

用Flex 调用java 连数据库和一些主要功能的实现

  • 2011年08月31日 14:14
  • 19.93MB
  • 下载

flex amfphp1.9

  • 2009年07月27日 18:54
  • 130KB
  • 下载

Flex:Openfire之SparkWeb开发环境搭建历程分享

春节后因项目需要,研究了把XMPP/Openfire,此前曾玩过spark,基于JAVA写的客户端,总觉得用Swing做的界面比较丑,作为IM客户端运行效率也不行(做个ERP,深有感触)。...
  • huanghr_1
  • huanghr_1
  • 2011-02-12 23:03:00
  • 8736

Flex获取MySQL数据库数据

我的环境为:Flash Builder4.6+MyEclipse10.6+MySQL5.6+32位Win7旗舰版 参考文章: http://kb.cnblogs.com/page/77057/ ...
  • friendan
  • friendan
  • 2013-11-22 18:16:42
  • 3147

Flex直接与mysql数据库连接

http://ns.adobe.com/mxml/2009"      xmlns:s="library://ns.adobe.com/flex/spark"      creationComplet...
  • sjz168
  • sjz168
  • 2011-07-29 10:34:53
  • 1492

Flex访问SQL Server数据库的方法

做一个“用户登录”的界面,自然用到了数据库操作,而Flex不能自己访问数据库,因而采用借助Web Service来访问的方法,具体流程如下: 1、用VS2008中asp.net发布一个WebServ...
  • zss793648186
  • zss793648186
  • 2014-05-13 22:37:23
  • 737

Flex存储图片到数据库的例子

 As代码:http://www.adobe.com/2006/mxml" layout="absolute" fontSize="12" creationComplete="init()">    ...
  • newskl
  • newskl
  • 2009-09-10 13:51:00
  • 2721

flex显示数据库表中的所有数据

flex显示数据库表中的所有数据,我通过调用远程对象来实现。 flex调用远程对象,服务器端我使用的是BlazeDS,我的另一篇文章讲到了如何搭建BlazeDS环境, 文章地址是:http://b...
  • friendan
  • friendan
  • 2013-11-29 19:22:14
  • 3266

flex连接到FMS详解

  • 2011年04月22日 15:52
  • 592KB
  • 下载
收藏助手
不良信息举报
您举报文章:Flex 连数据库
举报原因:
原因补充:

(最多只允许输入30个字)