IMHO anonymous  functions are way more trouble than they are worth.  If I had 
the time, I would eliminate them from all framework code.

Looks from the stacktrace that someone is using apply() to change the this 

On 9/22/11 10:46 AM, "grimmwerks" <> wrote:

Not getting an error, just getting ignored and the function is never called.

var scope:Object = this;
private var echoOrderCacheEvent:Function = function(jstr:String):void{;


I've tried the old pass through - but it's definitely not working properly; the 
'this' that's getting called within the function is NOT the function  - it's a 
SubscriptionListener in the stomp framework as that's what's calling the 
callback through the interface; something another dev has created and just want 
to come back with enough ammunition that the callbacks aren't being set 

It seems to me that he's creating another anonymous function as part of the 
stomp dispatching and then everything is getting lost:

ReferenceError: Error #1069: Property com.investlab.mix.common.model::scope not 
found on interbahn.SubscriptionListener and there is no default value.

On Sep 22, 2011, at 1:32 PM, Alex Harui wrote:

I don’t know why passing in echoEvent wouldn’t work.  What error did you get?

Another options are to pass in a third parameter as the object for use in call 
or apply.

You can theoretically do this as well in the constructor of the class:
Public function MyClassConstructor()
    var thisObject:Object = this;
    echoOrderCacheEvent = function(jstr:String):void{
        trace(thisObject);  // use ‘thisObject’ instead of ‘this’

On 9/22/11 9:50 AM, "grimmwerks" <> wrote:

OK I don't mean to make this a bit convoluted - but I guess the basics of the 
question is regarding using anonymous functions within a member class and being 
able to set variables within that member class.

The convoluted question is this:  I've got in my app an Interface class that 
has pointers to scala/java functions and are passed in callbacks like so:

function echoOrderEvent(callback:Function):void ;

function echoOrderCacheEvent(callback:Function,extension:Object):void ;
                                                               &n! bsp;

Now in my class I create vars as functions for callbacks like so:

private var echoOrderCacheEvent:Function = function(jstr:String):void{"GOT ORDER EVENT ");

I set up the call back to this function as such:

interfaceClass.echoOrderCacheEvent(echoOrderCacheEvent, {correlationId: 
 ! ;
Now, this works great except in the anonymous function I don't have any access 
to the public or private member vars of the class - only of course if I make 
the vars static, which is not what I want to do.

What I *can't* figure out is how to make the callback a regular member function 
such as:

public function echoEvent(str:String):void{
blah blah

And have that work with the interface class -- as 
interfaceClass.echoOrderCacheEvent(echoEvent, {correlationId: sessionId}) won't 
work; what I was thinking was perhaps .call or .apply methods but not sure how 
best to use them here...

Garry Schafer
portfolio: <>  

Alex Harui
Flex SDK Team
Adobe System, Inc.

Reply via email to