Adobe Flash Builder 4 +myeclipse开发中的问题

Ryo6688 2010-12-03 03:14:36
用的Adobe Flash Builder 4的BLazeDs连接数据服务,以可以通信问题是:

updateyh.mxml里:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:services="services.*">

<fx:Script>
<![CDATA[
import mx.controls.Alert;

import valueObjects.YongHu;

protected function update_clickHandler(event:MouseEvent):void
{
var yhn:YongHu=new YongHu();
yhn.username=username.text;
yhn.pwd=npwd.text;
updateusersResult.token = operUser.updateusers(yhn);
Alert.show(updateusersResult.lastResult);
if(updateusersResult.lastResult == true){
Alert.show("修改成功!");
}else{
Alert.show("修改失败!");
} }


]]>
</fx:Script>

<fx:Declarations>
<services:OperUser id="operUser" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="selectbyusenameResult"/>
<s:CallResponder id="selectbypwdResult"/>
<s:CallResponder id="updateusersResult"/>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Label y="92" text="用户名:" horizontalCenter="-88"/>
<s:TextInput y="83" horizontalCenter="3" id="username"/>
<s:Label y="153" text="旧密码:" horizontalCenter="-88"/>
<s:Label y="218" text="新密码:" horizontalCenter="-88"/>
<s:TextInput y="143" horizontalCenter="3" id="pwd"/>
<s:TextInput y="208" horizontalCenter="3" id="npwd"/>
<s:Button y="283" label="修 改" id="update" click="update_clickHandler(event)" horizontalCenter="-72"/>
<s:Label y="93" text="{selectbyusenameResult.lastResult}" id="a" horizontalCenter="119" color="#E53939"/>
<s:Label y="153" text="{selectbypwdResult.lastResult}" id="b" horizontalCenter="118" color="#E53939"/>
</s:WindowedApplication>

所得的值在第一次点击修改的时候是空,点击第2次才是java那边传过来的值,怎么回事???

java方法代码:
package com.zg.oper;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;

import com.zg.db.ConnectDB;
import com.zg.voo.YongHu;

public class OperUser {

private Connection conn;
private PreparedStatement pstmt;
private ResultSet rs;

//修改用户信息
public boolean updateusers(YongHu yh){
boolean flag=false;
conn=new ConnectDB().getConn();
try {
String sql="update zjcf_yonghu set Pwd=? where Username=?";
pstmt=conn.prepareStatement(sql);
pstmt.setString(1, yh.getPwd());
pstmt.setString(2, yh.getUsername());
//System.out.println(yh.getUsername());
//System.out.println(yh.getPwd());
int count=pstmt.executeUpdate();
if(count>0){
return true;
}
} catch (SQLException e) {

e.printStackTrace();
}finally{

try {
if( pstmt != null )
pstmt.close();
if( conn != null )
conn.close();
} catch (SQLException e) {

e.printStackTrace();
}
}
return flag;
}

}
...全文
269 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
Ryo6688 2010-12-06
  • 打赏
  • 举报
回复
问题解决:

少了import mx.rpc.events.ResultEvent;

Ryo6688 2010-12-06
  • 打赏
  • 举报
回复
错了,是:

<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" xmlns:services="services.*">

<fx:Script>
<![CDATA[
import mx.controls.Alert;

import valueObjects.YongHu;

protected function update_clickHandler(event:MouseEvent):void
{

var yhn:YongHu=new YongHu();
yhn.username=username.text;
yhn.pwd=npwd.text;
updateusersResult.token = operUser.updateusers(yhn);

}

private function resultHandler(event:ResultEvent):void{
if(event.result!=true){
Alert.show("修改成功!");
}else{
Alert.show("修改失败!");
}
}


]]>
</fx:Script>

<fx:Declarations>
<services:OperUser id="operUser" fault="Alert.show(event.fault.faultString + '\n' + event.fault.faultDetail)" showBusyCursor="true"/>
<s:CallResponder id="selectbyusenameResult"/>
<s:CallResponder id="selectbypwdResult"/>
<s:CallResponder id="updateusersResult" result="resultHandler()"/>
<!-- 将非可视元素(例如服务、值对象)放在此处 -->
</fx:Declarations>
<s:Label y="92" text="用户名:" horizontalCenter="-88"/>
<s:TextInput y="83" horizontalCenter="3" id="username"/>
<s:Label y="153" text="旧密码:" horizontalCenter="-88"/>
<s:Label y="218" text="新密码:" horizontalCenter="-88"/>
<s:TextInput y="143" horizontalCenter="3" id="pwd"/>
<s:TextInput y="208" horizontalCenter="3" id="npwd"/>
<s:Button y="283" label="修 改" id="update" click="update_clickHandler(event)" horizontalCenter="-72"/>
<s:Label y="93" text="{selectbyusenameResult.lastResult}" id="a" horizontalCenter="119" color="#E53939"/>
<s:Label y="153" text="{selectbypwdResult.lastResult}" id="b" horizontalCenter="118" color="#E53939"/>
<s:Label x="397" y="292" text="{updateusersResult.lastResult}" id="c"/>
</s:WindowedApplication>

1046: 找不到类型,或者它不是编译时常数: ResultEvent。
Ryo6688 2010-12-06
  • 打赏
  • 举报
回复
按上面的说法:代码有错的
<s:Button y="283" label="修 改" id="update" result="resultHandler()">
private function resultHandler(event:ResultEvent):void{
var yhn:YongHu=new YongHu();
yhn.username=username.text;
yhn.pwd=npwd.text;
updateusersResult.token = operUser.updateusers(yhn);
if(event.result!=true){
Alert.show("修改成功!");
}else{
Alert.show("修改失败!");
}
}

此行的多个标记:
-1046: 找不到类型,或者它不是编译时常数: ResultEvent。
-protected
leemiki 2010-12-03
  • 打赏
  • 举报
回复
这是一个异步通信问题

点第一次
updateusersResult.token = operUser.updateusers(yhn);//后执行
Alert.show(updateusersResult.lastResult);//先执行

点第二次:updateusersResult已经执行完,所以能取到值~~~

解决方案:
<s:CallResponder id="updateusersResult" result="resultHandler()"/>
private function resultHandler(event:ResultEvent):void{
event.result//执行完后台update操作返回到Flex端的值,根据它来判断时候修改成功即可
}
Ryo6688 2010-12-03
  • 打赏
  • 举报
回复
我没说清楚吗,为什么把updateusersResult.lastResult写在<s:Label y="153" text="{updateusersResult.lastResult}" id="b">上就能第1次得到值,写在
protected function update_clickHandler(event:MouseEvent):void
{
Alert.show(updateusersResult.lastResult);
}
里,点修改按钮第1次得到的是空,继续点第2次才能得到java里传过来的BOOLEN值,我想根据这个值判断做出相应的修改成功否的提示,怎么能解决?对于做过的人来说不难吧?
水中影子 2010-12-03
  • 打赏
  • 举报
回复
发到 Flex区吧
Ryo6688 2010-12-03
  • 打赏
  • 举报
回复
好像没人会的样子??顶!

4,328

社区成员

发帖
与我相关
我的任务
社区描述
多媒体/设计 Flex
社区管理员
  • Flex
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧