个人总结flex各种用法

2024-09-28

个人总结flex各种用法(通用2篇)

个人总结flex各种用法 篇1

自己用的一个SQLite操作类,包括AIRSQLite,SqlParameter这两个类。用的都是静态的方法,使用的时候不用创建实例,直接引用就可以的。

例如:

AIRSQLite.setLocalSQLServer(“d:/test.db”)就在d盘根目录下新建了名为test的数据库。提供了建表查询删除等等的方法,自己可以扩展的„„SqlParameter

============================================= AIRSQLite.as

package

{

import flash.data.SQLConnection;import flash.data.SQLMode;import flash.data.SQLResult;import flash.data.SQLStatement;import flash.errors.SQLError;import flash.filesystem.File;public class AIRSQLite {// 数据库连接字串 public static var localSQLServer:SQLConnection = new SQLConnection();public function AIRSQLite(){ }// 连接数据库 public static function setLocalSQLServer(dbURL:String):Boolean {} try {} catch(error:Error){} return true;return false;var dbFile:File = File.applicationDirectory.resolvePath(dbURL);if(localSQLServer.connected){} localSQLServer.open(dbFile, SQLMode.UPDATE);return true;

// 执行SQL语句,返回影响的记录数

public static function executeSql(conn:SQLConnection, sqlString:String,cmdParams:SqlParameter):int

{

var result:SQLResult = querySQL(conn, sqlString, cmdParams);

return result.rowsAffected;

}

// 执行查询语句,返回结果数组 public static function query(conn:SQLConnection, sqlString:String, {}// 执行查询语句,返回结果 public static function querySQL(conn:SQLConnection, sqlString:String, {} var sqlstatement:SQLStatement = new SQLStatement();sqlstatement.sqlConnection = conn;sqlstatement.text = sqlString;try {} catch(error:SQLError){} return sqlstatement.getResult();trace(error.details);throw SQLError;if(cmdParams.length > 0){} sqlstatement.execute();//cmdParams.clear();cmdParams.transParameters(sqlstatement);var result:SQLResult = querySQL(conn, sqlString, cmdParams);return result.data;cmdParams:SqlParameter):Array cmdParams:SqlParameter):SQLResult

// 检测一个记录是否存在public static function exists(conn:SQLConnection, sqlString:String,cmdParams:SqlParameter):Boolean

{

var result:Array = query(conn, sqlString, cmdParams);

return result.length > 0;

}

// 获取表某个字段的最大值

public static function getMaxID(conn:SQLConnection, FieldName:String,TableName:String):uint

{

var sql:String = “SELECT MAX(” + FieldName + “)FROM ” + TableName;

var result:Array = query(conn, sql, new SqlParameter());

if(result[0][FieldName]!= null)

return result[0][FieldName];

else

return 0;

}

//总记录数

public static function getRecordNum(conn:SQLConnection, TableName:String,FieldName:String, cmdParams:SqlParameter, wheresql:String = “"):uint

{

var sql:String = ”SELECT COUNT(“ + FieldName + ”)FROM “ + TableName;

sql += ” “+wheresql;

var result:Array = query(conn, sql, cmdParams);

return uint(result[0][”COUNT(“+FieldName+”)“].toString());

}

//pageSize 每页数据量

//pageIndex 页数

public static function pageList(conn:SQLConnection, sqlString:String,cmdParams:SqlParameter, pageSize:uint, pageIndex:uint):Array

{

sqlString += ” LIMIT “+(pageSize*(pageIndex-1)).toString()+”, “+pageSize.toString();return query(conn, sqlString, cmdParams);

}

}

============================================= } SqlParameter.as

package

{

import flash.data.SQLStatement;

}

public dynamic class SqlParameter extends Object {} public function SqlParameter(){ }//给SQLStatement参数赋值 public function transParameters(SQLStatementParameters:SQLStatement):void {}//清除全部属性 public function clear():void {}//获取属性数量 public function get length():uint {}var len:uint = 0;for(var i:String in this){} return len;len ++;for(var i:String in this){} delete this[i];for(var i:String in this){} SQLStatementParameters.parameters[i] = this[i];

============================================= 用法:

整个类非常的简单,使用起来也简单,例如删除记录代码:

//首先连接数据库,alert.sqlite是示例所用到的数据库名

if(!AIRSQLite.setLocalSQLServer(“alert.sqlite”))

{

trace(“连接数据库失败”);

}

//delete

public static function deleteDB(PKId:uint):Boolean

{

//SQL字符串

var sql:String = “Delete FROM EventTable Where PKId=@PKId”;

var parameters:SqlParameter = new SqlParameter();

//参数

parameters[”@PKId“] = PKId;

//执行

return AIRSQLite.executeSql(AIRSQLite.localSQLServer, sql, parameters)>0;

}

//查询语句

public static function viewDB(PKId:int = 0):Array

{

var sql:String = “Select * FROM EventTable “;

var parameters:SqlParameter = new SqlParameter();

if(PKId!= 0)

{

sql += “Where PKId=@PKId”;

parameters[”@PKId“] = PKId;

}

var result:Array = AIRSQLite.query(AIRSQLite.localSQLServer, sql, parameters);

for(var i:int = 0;i < result.length;i++)

{

var output:String = ”“;

var row:Object = result[i];

for(var prop:String in row)

{

output += prop+”:“+row[prop]+”, ";

}

trace(output);

return result;}

flex整合Java登陆总结 篇2

1、环境的搭建:

对message-congig.xml配置如下:

Web.xml的配置如下:

BlazeDS

BlazeDS Application

flex.messaging.HttpFlexSession

MessageBrokerServlet class=“flex.messaging.services.RemotingService”>

class=“flex.messaging.services.remoting.adapters.JavaAdapter” default=“true” />

com.wangkun.Login

flex.messaging.MessageBrokerServlet

services.configuration.file

/WEB-INF/flex/services-config.xml

1

MessageBrokerServlet

/messagebroker/*

这些xml文件基本固定。

2、创建Bean类User和Login类

public class Login {

} 启动tomcat,至此myeclipse里的配置结束。

3、在flah builder里创建一个flex项目。public String login(String name, String psw){

} public String login(User user){

}

public User login(){ } return new User(“wang”,“aaa”,33);if(“sss”.equals(user.getName())&&

} return “good”;return “sorry”;if(“aa”.equals(name)&& “123”.equals(psw)){

} return “ok”;return “error”;} else {

“123”.equals(user.getPwd())){ }else{

应用服务器技术类型选:j2ee BalzeDS 下一步之后配置服务器位置:

点击完成。

4、对index.mxml的编写:

首先要在fx:Decaration中配置destination对应于message-congig.xml中的id Result是回调函数,

endpoint=“/flexApp01/messagebroker/amf”>

Fx:script中的代码如下:

import com.wang.asclass.User;

import mx.controls.Alert;import mx.rpc.events.ResultEvent;protected function huidiao1(event:ResultEvent):void { // TODO Auto-generated method stub

var result:String =event.result as String;

]]> } Alert.show(result,“结果”);protected function huidiao2(event:ResultEvent):void { // TODO Auto-generated method stub

var result:User = event.result as User;Alert.show(result.name);trace(result.name);} protected function senddata(event:MouseEvent):void //按确认按钮时 {

} protected function canceldata(event:MouseEvent):void //按取消按钮时 {

}

protected function showdata(event:MouseEvent):void{ //按查询按钮

} loginClientTag2.login();// TODO Auto-generated method stub

var name:String=this.nametext.text;var psw :String=this.pswtext.text;var user :User = new User();user.name=name;user.pwd=psw;loginClientTag.login(user);

// TODO Auto-generated method stub

this.nametext.text=“";this.pswtext.text=”“;

视图:

可创建一个名为User的as类 package com.wang.asclass {

}

[Bindalbe] [RemoteClass(alias=”com.wangkun.User")] public class User {

上一篇:经典的微信人生感悟句子下一篇:京东商城经营战略