Just an FYI. It was elsewhere, the mainApp var wasn't initialized. And I'm quite happy because this approach is working great!

On Mar 24, 2006, at 12:05 PM, Chris Scott wrote:

OK, I'm completely almost there, but something is still a little 
crazy. So I'll take a step back. OK, so in my main app I have a 
RemoteObject defined like so:

<mx:RemoteObject id="userService" destination="UserService"
        result="event.call.resultHandler(event)">
        <mx:method name="authenticateUser"/>
    </mx:RemoteObject>

and I have a custom component there also, in a view state, you see 
I'm giving it a reference to the userService:

<Login id="login" right="20" bottom="20" userService="{userService}" />

So now in the login component I am going to call authenticateUser, 
and there I will set the resultHandler:

// login methods
public function attemptLogin():void {
        var userId:String = usrId.text;
      var password:String = pwd.text;
        var pendingCall:AsyncToken;

      pendingCall = userService.authenticateUser(userId, password);
         pendingCall.resultHandler = loginResult;
}

public function loginResult(event:ResultEvent):void {
        var user:User;

        Alert.show('Retrieved: '+event, 'Result');
         Alert.show('?Result: '+event.result, 'Result');

        if (event.result != null) {
              // store in parent, go to dashboard
              user = User(event.result);
              mainApp.setUser(user);
              mainApp.showDashboard();
         } else {
              errorText = "Sorry, account not found! Please try again.";
              showError();
        }
}

OK, so here's what happens. If my remote service returns null (no 
user found) it's fine. The first alert shows the event, and the 
second shows that the event.result is null. Now if my remote service 
returns a User object, I FIRST get an error: ERROR #1009: null has no 
properties, then I get the second Alert (?Result: [object User]) on 
top of the first. Wow, that's totally odd. Anyone? Maybe I am totally 
trying to do this completely wrong. But it's real important that I 
can build this up to a proper use of delegates and command objects, 
or I'm gonna have a real bad time with architecture later on. Thanks!


On Mar 24, 2006, at 11:46 AM, Ted Patrick wrote:

> Chris,
>
> AS3 supports method closure. This assures that every method and 
> function is always executed in the scope where it was defined. Here 
> is a simple example:
>
> function doIt(){ trace(this) }
>
> a = new Object()
>
> a.b = doIt
>
> a.b() //doIt is executed in the scope where it was defined not 
> within ‘a’
>
> Even using reference to a function, the executing function/method 
> is always in the scope where it was originally defined.
>
> When you listen for events, you can simply pass a reference to a 
> method within an instance and the event will be called in the scope 
> of the instance.
>
> It makes life so much simpler!
>
> Cheers,
>
> Cynergy Systems, Inc.
> Theodore Patrick
> Sr. Consultant
> [EMAIL PROTECTED]
> tel: 1.866.CYNERGY
> http://www.cynergysystems.com
>
> --
> No virus found in this outgoing message.
> Checked by AVG Free Edition.
> Version: 7.1.385 / Virus Database: 268.3.1/291 - Release Date: 
> 3/24/2006
>
>
>
> --
> Flexcoders Mailing List
> FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
> Search Archives: http://www.mail-archive.com/flexcoders%
> 40yahoogroups.com
> Yahoo! Groups Links
>
>
>
>
>
>

Chris Scott
[EMAIL PROTECTED]
http://cdscott.blogspot.com/
http://www.coldspringframework.org/



--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




<TeamFusionD.gif>







Reply via email to