Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 01-02-2009, 01:04 AM   #1
frasseff
Registered User
 
Join Date: Jan 2009
Posts: 3
Default access Responder using NetConnection

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)

ActionScript Code:
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

ActionScript Code:
<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
frasseff is offline   Reply With Quote
Old 01-06-2009, 11:41 AM   #2
Sly_cardinal
Senior Member
 
Join Date: Mar 2004
Location: Australia
Posts: 318
Default

Do not redeclare the 'netConnection' variable inside your constructor.

Do this instead:
ActionScript Code:
public function remoteObj()         {             netConnection = new NetConnection();             netConnection.connect("MYURL");             var responder:Responder = new Responder(onComplete, onFail);             netConnection.call("exposed.getAllLandpoly", responder);                }

The problems is that you are declaring a new local variable that is obscuring your class member declaration of 'netConnection'. Then when the constructor completes the local variable is garbage collected.
Sly_cardinal is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
[Q] Setting up connection between MS Access and PHP... CyanBlue Server-Side Scripting 23 05-04-2009 11:05 AM
Cannot Access Text within Cross Domain SWF scantron13 ActionScript 2.0 1 12-09-2008 12:21 PM
Netconnection call can't get responder in AS2 monkeyvu ActionScript 2.0 1 10-22-2008 03:42 AM
1120: Access of undefined property videofile yodasw16 Components 5 04-21-2008 06:28 PM
XML/DB data access question(s) CDHBookingEdge Flex 2, 3 & 4 4 11-03-2006 07:19 AM


All times are GMT. The time now is 01:43 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.