[flexcoders] help with anonymous functions...

2011-09-22 Thread grimmwerks
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 ;

 

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
gr...@grimmwerks.com
portfolio: www.grimmwerks.com/







Re: [flexcoders] help with anonymous functions...

2011-09-22 Thread Alex Harui
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 gr...@grimmwerks.com 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
gr...@grimmwerks.com
portfolio: www.grimmwerks.com/ http://www.grimmwerks.com/










--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


Re: [flexcoders] help with anonymous functions...

2011-09-22 Thread grimmwerks
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{
Alert.show(this);
trace(scope);

}

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 
properly:

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.
at 
Function/anonymous()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/com/investlab/mix/common/model/OrderProxyNew.as:142]
at 
interbahn::SubscriptionListener/apply()[C:\transfer\IdeaProjects\as3-interbahn\main\as3\src\interbahn\SubscriptionListener.as:59]
at 
Function/anonymous()[C:\transfer\IdeaProjects\as3-interbahn\main\as3\src\interbahn\stomp\StompConnection.as:35]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at 
org.codehaus.stomp::Stomp/dispatchFrame()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:350]
at 
org.codehaus.stomp::Stomp/processFrame()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:326]
at 
org.codehaus.stomp::Stomp/onData()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:312]



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 gr...@grimmwerks.com 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
 gr...@grimmwerks.com
 portfolio: www.grimmwerks.com/ http://www.grimmwerks.com/ 
 
 
 
 
 
  

 
 
 
 -- 
 Alex Harui
 Flex SDK Team
 Adobe System, Inc.
 http://blogs.adobe.com/aharui
 
 
 

Garry Schafer
grimmwerks
gr...@grimmwerks.com
portfolio: www.grimmwerks.com/







Re: [flexcoders] help with anonymous functions...

2011-09-22 Thread Alex Harui
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 
pointer.


On 9/22/11 10:46 AM, grimmwerks gr...@grimmwerks.com 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{
Alert.show(this);
trace(scope);

}

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 
properly:

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.
at 
Function/anonymous()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/com/investlab/mix/common/model/OrderProxyNew.as:142]
at 
interbahn::SubscriptionListener/apply()[C:\transfer\IdeaProjects\as3-interbahn\main\as3\src\interbahn\SubscriptionListener.as:59]
at 
Function/anonymous()[C:\transfer\IdeaProjects\as3-interbahn\main\as3\src\interbahn\stomp\StompConnection.as:35]
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at 
org.codehaus.stomp::Stomp/dispatchFrame()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:350]
at 
org.codehaus.stomp::Stomp/processFrame()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:326]
at 
org.codehaus.stomp::Stomp/onData()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:312]



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 gr...@grimmwerks.com 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
gr...@grimmwerks.com
portfolio: www.grimmwerks.com/ http://www.grimmwerks.com/  
http://www.grimmwerks.com/










--
Alex Harui
Flex SDK Team
Adobe System, Inc.
http://blogs.adobe.com/aharui


Re: [flexcoders] help with anonymous functions...

2011-09-22 Thread grimmwerks
Thanks  -- yeah it seems like the something's happening on the stomp / callback 
before it's getting to me.

Have another quickie about itemrenderers and factory properties, but going to 
ask on another thread.

On Sep 22, 2011, at 2:11 PM, Alex Harui wrote:

 
 
 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 
 pointer.
 
 
 On 9/22/11 10:46 AM, grimmwerks gr...@grimmwerks.com 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{
 Alert.show(this);
 trace(scope);
 
 }
 
 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 properly:
 
 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.
 at 
 Function/anonymous()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/com/investlab/mix/common/model/OrderProxyNew.as:142]
 at 
 interbahn::SubscriptionListener/apply()[C:\transfer\IdeaProjects\as3-interbahn\main\as3\src\interbahn\SubscriptionListener.as:59]
 at 
 Function/anonymous()[C:\transfer\IdeaProjects\as3-interbahn\main\as3\src\interbahn\stomp\StompConnection.as:35]
 at flash.events::EventDispatcher/dispatchEventFunction()
 at flash.events::EventDispatcher/dispatchEvent()
 at 
 org.codehaus.stomp::Stomp/dispatchFrame()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:350]
 at 
 org.codehaus.stomp::Stomp/processFrame()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:326]
 at 
 org.codehaus.stomp::Stomp/onData()[/Users/grimm/Documents/__WORK/__INVESTLAB/MIX/src/org/codehaus/stomp/Stomp.as:312]
 
 
 
 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 gr...@grimmwerks.com 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 -- 
 asinterfaceClass.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
 gr...@grimmwerks.com
 portfolio: www.grimmwerks.com/ http://www.grimmwerks.com/  
 http://www.grimmwerks.com/ 
 
 
 
 
 
  

 
 
 
 -- 
 Alex Harui
 Flex SDK Team
 Adobe System, Inc.
 http://blogs.adobe.com/aharui
 
 
 

Garry Schafer
grimmwerks
gr...@grimmwerks.com
portfolio: