views:

593

answers:

5

hi guys,

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?

+1  A: 

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.

Herms
A: 

yeah thats the webservice call, when the result comes in it calls getNameResults

combi001
You need to expand the code you are showing then. At the moment, it just looks like you are calling the wrong method. We'd need to see the code that calls getNameResults()
David Arno
+2  A: 

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 yeilds 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?

Ryan Guill
A: 

ok cool, i see what our saying,will try it out

combi001
A: 

I m getting [ObjectAsyncToken] in variable a instead of string, as i m retriving 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;

}

Anirudha