简体   繁体   English

flex3函数无法正确返回String

[英]flex3 function not returning String properly

im trying to return a string value from a method inside my script tag however it always returns an object and i cant get at the string value. 我试图从我的脚本标签内的方法返回一个字符串值,但是它总是返回一个对象,而我无法获得该字符串值。

Here is the code: 这是代码:

i retrieve the object returned from a webservice call;; 我检索从网络服务调用返回的对象;

    private function getNameResults(e:ResultEvent):String{
     var name:Array = new Array(e.result);
     var site:String = site_names[0].toString();
     Alert.show("site - " +site);
     return site;
}

the alert prints out the name fine, however when i try use the value in my next method (which calls the web service which calls getNameResults) i get the object tag 警报可以很好地打印出名称,但是当我尝试在下一个方法(调用调用getNameResults的Web服务)中使用该值时,我得到了对象标记

private function getInfo(roomName:String):String{
    var site:String =userRequest.getRoomZoneInfo(roomName);
    return site;
}

however the value returned here is [object AsyncToken] 但是,这里返回的值是[object AsyncToken]

any ideas? 有任何想法吗?

You are setting the result of getRoomZoneInfo() to the variable site, but you are casting it as a String. 您将getRoomZoneInfo()的结果设置为变量站点,但是将其强制转换为String。 getRoomZoneInfo is returning an object, and because the variable you are sticking it in is a string it is like calling .toString() on the object, which yields the [object AsyncToken ]. getRoomZoneInfo返回一个对象,并且因为您要粘贴的变量是字符串,所以就像在对象上调用.toString()一样,这会产生[object AsyncToken ]。

Basically if getRoomZoneInfo is a webservice call, you cannot get the information you are looking for here, you have to wait until the result comes back and get the string you are looking for there. 基本上,如果getRoomZoneInfo是一个Web服务调用,则无法在此处获取所需的信息,必须等到结果返回并在那里获取所需的字符串。 Make sense? 说得通?

Your getInfo() method isn't calling getNameResults(). 您的getInfo()方法未调用getNameResults()。 It's calling getRoomZoneInfo(). 它正在调用getRoomZoneInfo()。 I don't know what that method does, but I'm guessing it's returning an Object, not a String. 我不知道该方法的作用,但是我猜测它返回的是对象,而不是字符串。

I m getting [ ObjectAsyncToken ] in variable a instead of string, as I'm retrieving data from database 我从变量中获取[ ObjectAsyncToken ]而不是字符串,因为我正在从数据库中检索数据

private function init():void
{
   ro.initView();
   var a:String=String(ro.getID());
}

database function: 数据库功能:

public void initView()
{
  try
  {
    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
    Connection conn = DriverManager.getConnection("jdbc:odbc:alarmdsn"," "," ");
    Statement s = conn.createStatement();
    ResultSet r = s.executeQuery("select * from alarm");
    while(r.next()) {
      a = r.getString(1);             
    }
  }
  catch(Exception e) {}
}

public String getID() {
   return a;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM