Question

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

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

however the value returned here is [object AsyncToken]

any ideas?

Was it helpful?

Solution

You are setting the result of getRoomZoneInfo() to the variable site, but you are casting it as a 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].

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. Make sense?

OTHER TIPS

Your getInfo() method isn't calling getNameResults(). It's calling 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

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top