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" <[email protected]> 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 ;
[UriParams(p1="correlationId")]
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{
Alert.show("GOT ORDER EVENT ");
}
I set up the call back to this function as such:
interfaceClass.echoOrderCacheEvent(echoOrderCacheEvent, {correlationId:
sessionId});
!
! ;
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
grimmwerks
[email protected]
portfolio: www.grimmwerks.com/ <http://www.grimmwerks.com/>
--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui