frasseff
01-02-2009, 02:04 AM
Hi all
I am new in flex. I am trying to access server using NetConnection and than collect the results from Responder. If have my code in .mxml file it is working. but If if I put same code in .as file as a class than the results is empty. the onComplete function run in some magic event.
Here is my code when its is not work (in .as file)
package dipclasses
{
import flash.events.Event;
import flash.net.*;
public class remoteObj
{
private var netConnection:NetConnection;
public static var resString:String; // I am tryin to collet data in this but it is not working
public function remoteObj()
{
var netConnection:NetConnection = new NetConnection();
netConnection.connect("MYURL");
var responder:Responder = new Responder(onComplete, onFail);
netConnection.call("exposed.getAllLandpoly", responder);
}
private function onComplete(results):void {
var res:Object= results;
for (var r:Object in res)
{
resString += r + " : " + res[r];
}
}
function onFail(results):void {
var failString:String;
for each (var thisResult in results){
failString += thisResult;
}
resString = failString;
}
}
}
Here the working code in .mxml file
<mx:Script>
<![CDATA[
public function initApp(): void
{
var netConnection:NetConnection = new NetConnection();
netConnection.connect("MYURL");
var responder:Responder = new Responder(onComplete, onFail);
netConnection.call("exposed.getAllLandpoly", responder);
}
function onComplete(results) {
var res:Object= results;
for (var r:Object in res)
{
UserMessage.text += r + res[r];
}
}
function onFail(results) {
for each (var thisResult in results){
UserMessage.text += thisResult;
}
}
]]>
</mx:Script>
Thanx
Frasse
I am new in flex. I am trying to access server using NetConnection and than collect the results from Responder. If have my code in .mxml file it is working. but If if I put same code in .as file as a class than the results is empty. the onComplete function run in some magic event.
Here is my code when its is not work (in .as file)
package dipclasses
{
import flash.events.Event;
import flash.net.*;
public class remoteObj
{
private var netConnection:NetConnection;
public static var resString:String; // I am tryin to collet data in this but it is not working
public function remoteObj()
{
var netConnection:NetConnection = new NetConnection();
netConnection.connect("MYURL");
var responder:Responder = new Responder(onComplete, onFail);
netConnection.call("exposed.getAllLandpoly", responder);
}
private function onComplete(results):void {
var res:Object= results;
for (var r:Object in res)
{
resString += r + " : " + res[r];
}
}
function onFail(results):void {
var failString:String;
for each (var thisResult in results){
failString += thisResult;
}
resString = failString;
}
}
}
Here the working code in .mxml file
<mx:Script>
<![CDATA[
public function initApp(): void
{
var netConnection:NetConnection = new NetConnection();
netConnection.connect("MYURL");
var responder:Responder = new Responder(onComplete, onFail);
netConnection.call("exposed.getAllLandpoly", responder);
}
function onComplete(results) {
var res:Object= results;
for (var r:Object in res)
{
UserMessage.text += r + res[r];
}
}
function onFail(results) {
for each (var thisResult in results){
UserMessage.text += thisResult;
}
}
]]>
</mx:Script>
Thanx
Frasse