Re: [flexcoders] Functions as objects

2006-12-08 Thread Anatole Tartakovsky

Francis,
 It worked in betas, but was removed on production build - we had to remove
samples from the chapter. In standard mode fails for us on access as well
with runtime error. More importantly, we can not extend Function datatype as
runtime fails instantiation stating that type Function is final. If that
restriction is removed, very cool OO tricks can be done.

Sincerely,
Anatole



On 12/8/06, Francis Cheng <[EMAIL PROTECTED]> wrote:


   You should be able to add properties to function objects, just as the
docs suggest. Unfortunately, it looks like this isn't working in strict mode
anymore. Oddly, it does work in standard mode, but that may not be a viable
workaround for you. I had a brief discussion about this with the engineers
that worked on it and their initial reaction was that this sounds like a
bug. I've filed it as such, and they will investigate it further.



Francis
 --

*From:* flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] *On
Behalf Of *Derek Vadneau
*Sent:* Wednesday, December 06, 2006 8:15 AM
*To:* flexcoders
*Subject:* [flexcoders] Functions as objects



I've tried using the example from the docs where you assign the value
to a property on the function and then use arguments.callee.prop to
get the value, but Flex Builder gives me an error saying "Access of
possibly undefined property prop through a reference with static type
Function." when assigning the value to the function.

Example:
function test()
{
trace(arguments.callee.prop);
}
test.prop = "testing"; // Error

Global.as <http://global.as/> defines Function as dynamic yet FB produces
an error.

This is supposedly possible in AS3 as per:
http://livedocs.macromedia.com/flex/2/docs/1835.html

However, if you try the last example you'll get compiler errors.

Is there a way to add properties to a function? Or is this not supported
in AS3?

--

Derek Vadneau





Re: [flexcoders] Functions as objects

2006-12-08 Thread Derek Vadneau

Thanks Clint! I completely forgot about describeType. That's MUCH better
than tacking on a property - not that you shouldn't be able to do that, but
describeType is better suited in this case.

And thank you, Francis, for looking into this. It's good to hear that I'm
not crazy! ... at least nothing proven here ...

--

Derek Vadneau


Re: [flexcoders] Functions as objects

2006-12-08 Thread Anatole Tartakovsky

Derek
So - just make setter method on closure object for function or define it as
a property - it's just an old good pointer.
Regards,
Anatole




On 12/8/06, Derek Vadneau <[EMAIL PROTECTED]> wrote:


  Funny, I just read that this morning. However, it doesn't really apply
here. I need to pass a function object and the name will probably be
different for each one. So assigning a value to a variable of the class
isn't acceptable, since the value will change for each call.

As I mentioned, I have a workaround, but I really want to know whether the
documentation is correct and I've simply missed something, or Adobe needs to
clean up the docs.



On 12/8/06, Anatole Tartakovsky <[EMAIL PROTECTED] > wrote:
>
>Please see apply method
> also I posted pre-edited cut from the book here:
> http://flexblog.faratasystems.com/?p=125  - with closure object ala Flex
> 1.5 you can use
>
> Thanks,
> Anatole
>
>
>
>



--

Derek Vadneau





RE: [flexcoders] Functions as objects

2006-12-08 Thread Francis Cheng
You should be able to add properties to function objects, just as the
docs suggest. Unfortunately, it looks like this isn't working in strict
mode anymore. Oddly, it does work in standard mode, but that may not be
a viable workaround for you. I had a brief discussion about this with
the engineers that worked on it and their initial reaction was that this
sounds like a bug. I've filed it as such, and they will investigate it
further. 

 

Francis



From: flexcoders@yahoogroups.com [mailto:[EMAIL PROTECTED] On
Behalf Of Derek Vadneau
Sent: Wednesday, December 06, 2006 8:15 AM
To: flexcoders
Subject: [flexcoders] Functions as objects

 

I've tried using the example from the docs where you assign the value
to a property on the function and then use arguments.callee.prop to
get the value, but Flex Builder gives me an error saying "Access of
possibly undefined property prop through a reference with static type
Function." when assigning the value to the function.

Example:
function test()
{
trace(arguments.callee.prop);
}
test.prop = "testing"; // Error

Global.as defines Function as dynamic yet FB produces an error.

This is supposedly possible in AS3 as per:
http://livedocs.macromedia.com/flex/2/docs/1835.html
<http://livedocs.macromedia.com/flex/2/docs/1835.html> 

However, if you try the last example you'll get compiler errors.

Is there a way to add properties to a function? Or is this not supported
in AS3?

-- 

Derek Vadneau

 



Re: [flexcoders] Functions as objects

2006-12-08 Thread Clint Modien

Here's some code to get the name of the currently executing function
dynamically if that's what you're after...

   var traceTarget:TraceTarget = new TraceTarget();

   // Log only messages for the classes in the mx.rpc.* and

   // mx.messaging packages.
   //traceTarget.filters=["mx.rpc.*","mx.messaging.*"];

   // Log all log levels.
   traceTarget.level = LogEventLevel.ALL;

   // Add date, time, category, and log level to the
output.
  // This is a bug right now... you can't include both date
and time.
   traceTarget.includeDate = false;
   traceTarget.includeTime = true;
   traceTarget.includeCategory = true;
   traceTarget.includeLevel = true;
   traceTarget.filters = ["com.esria.logging"];

   // Begin logging.

   var logger:ILogger = Log.getLogger("com.esria.logging");
   traceTarget.addLogger(logger);

   Log.addTarget(traceTarget);
   var d:String =  DateUtil.formatDate(new Date(),
"MM/DD/YYY");
   var x:XML = describeType(this);
   var memberName:String = "undefined";
   var members:XMLList = x.method.(@declaredBy==
this.className);
   for each(var member:XML in members) {
   memberName = [EMAIL PROTECTED];
   if (this[memberName] == arguments.callee)

break;
   }
   logger.debug("{0}.{1}", this.className, memberName);

Quick note... You should build a hasmap of each classes members that get
returned by (x.method.(@declaredBy==this.className); )  if you plan on using
it more than once to save looping over the classes variable names.

On 12/8/06, Derek Vadneau <[EMAIL PROTECTED]> wrote:


  Funny, I just read that this morning. However, it doesn't really apply
here. I need to pass a function object and the name will probably be
different for each one. So assigning a value to a variable of the class
isn't acceptable, since the value will change for each call.

As I mentioned, I have a workaround, but I really want to know whether the
documentation is correct and I've simply missed something, or Adobe needs to
clean up the docs.



On 12/8/06, Anatole Tartakovsky <[EMAIL PROTECTED] > wrote:
>
>   Please see apply method
> also I posted pre-edited cut from the book here:
> http://flexblog.faratasystems.com/?p=125  - with closure object ala Flex
> 1.5 you can use
>
> Thanks,
> Anatole
>
>
>
>



--

Derek Vadneau
 



Re: [flexcoders] Functions as objects

2006-12-08 Thread Derek Vadneau

Funny, I just read that this morning. However, it doesn't really apply here.
I need to pass a function object and the name will probably be different for
each one. So assigning a value to a variable of the class isn't acceptable,
since the value will change for each call.

As I mentioned, I have a workaround, but I really want to know whether the
documentation is correct and I've simply missed something, or Adobe needs to
clean up the docs.



On 12/8/06, Anatole Tartakovsky <[EMAIL PROTECTED]> wrote:


  Please see apply method
also I posted pre-edited cut from the book here:
http://flexblog.faratasystems.com/?p=125 - with closure object ala Flex
1.5 you can use

Thanks,
Anatole








--

Derek Vadneau


Re: [flexcoders] Functions as objects

2006-12-08 Thread Anatole Tartakovsky

Please see apply method
also I posted pre-edited cut from the book here:
http://flexblog.faratasystems.com/?p=125 - with closure object ala
Flex 1.5you can use

Thanks,
Anatole



On 12/8/06, Derek Vadneau <[EMAIL PROTECTED]> wrote:


  You shouldn't have to cast as an object. And, according to the docs, you
should be able to simply add a property to a function and access it. No
offense - I really do appreciate the effort to help me out - but casting
seems to be a bit of a hack. Although I like AS3 there are some things that
were so simple in AS1/AS2 that are just not possible, or require workarounds
that really seem like hacks.

All I wanted to do was give some context to a function so when it is
called it could grab that context info. An example of what people have
wanted from this from the MX days is getting the name of the function for
various reasons, including debugging and logging. My particular reason is a
little more complex and probably seems strange unless you know the entire
context of what I'm trying to do, but here goes ...

I built a class that extends Proxy. The idea is that someone would call a
function on the instance of the class and I would resolve it from a
dynamically added manifest. That part isn't hard, using the override for
callProperty. However, if someone tries to call a function using [] syntax
the getProperty override is actually called, and a function is expected to
be returned. Unfortunately, that scenario breaks what I was trying to
accomplish since it means I need to return an actual function object and the
function is not able to know it's name for me to determine if the call
should go through or return an error. I could determine this in the
getProperty override, but I don't necessarily know if the user meant to call
a function or access a property.

What I wanted to do was pass a function object back with a property on the
function that was the name of the function. Instead I've had to build a
class that stores a value in a variable and has a method on it that gets
returned from the getProperty override. That is such a waste considering
Function is supposed to be able to do what I want.

So, I have a workaround, but I really want to know whether the
documentation is correct and I've simply missed something, or Adobe needs to
clean up the docs. I've already posted a comment in the LiveDocs asking
about this and it has not yet been approved. That was about a week ago.

Can anyone else confirm this? Or does anyone know how to get the example
code working?


On 12/8/06, Clint Modien < [EMAIL PROTECTED]> wrote:
>
>   Function inherits from Object so you should be able to do...
>
> Object(this.test).prop = "someprop";
>
> Why are you doing this?  What are you trying to do... it sounds
> interesting.
>
> 



Re: [flexcoders] Functions as objects

2006-12-08 Thread Derek Vadneau

You shouldn't have to cast as an object. And, according to the docs, you
should be able to simply add a property to a function and access it. No
offense - I really do appreciate the effort to help me out - but casting
seems to be a bit of a hack. Although I like AS3 there are some things that
were so simple in AS1/AS2 that are just not possible, or require workarounds
that really seem like hacks.

All I wanted to do was give some context to a function so when it is called
it could grab that context info. An example of what people have wanted from
this from the MX days is getting the name of the function for various
reasons, including debugging and logging. My particular reason is a little
more complex and probably seems strange unless you know the entire context
of what I'm trying to do, but here goes ...

I built a class that extends Proxy. The idea is that someone would call a
function on the instance of the class and I would resolve it from a
dynamically added manifest. That part isn't hard, using the override for
callProperty. However, if someone tries to call a function using [] syntax
the getProperty override is actually called, and a function is expected to
be returned. Unfortunately, that scenario breaks what I was trying to
accomplish since it means I need to return an actual function object and the
function is not able to know it's name for me to determine if the call
should go through or return an error. I could determine this in the
getProperty override, but I don't necessarily know if the user meant to call
a function or access a property.

What I wanted to do was pass a function object back with a property on the
function that was the name of the function. Instead I've had to build a
class that stores a value in a variable and has a method on it that gets
returned from the getProperty override. That is such a waste considering
Function is supposed to be able to do what I want.

So, I have a workaround, but I really want to know whether the documentation
is correct and I've simply missed something, or Adobe needs to clean up the
docs. I've already posted a comment in the LiveDocs asking about this and it
has not yet been approved. That was about a week ago.

Can anyone else confirm this? Or does anyone know how to get the example
code working?


On 12/8/06, Clint Modien <[EMAIL PROTECTED]> wrote:


  Function inherits from Object so you should be able to do...

Object(this.test).prop = "someprop";

Why are you doing this?  What are you trying to do... it sounds
interesting.




Re: [flexcoders] Functions as objects

2006-12-07 Thread Clint Modien

Function inherits from Object so you should be able to do...

Object(this.test).prop = "someprop";

Why are you doing this?  What are you trying to do... it sounds interesting.

On 12/6/06, Derek Vadneau <[EMAIL PROTECTED]> wrote:


  I've tried using the example from the docs where you assign the value
to a property on the function and then use arguments.callee.prop to
get the value, but Flex Builder gives me an error saying "Access of
possibly undefined property prop through a reference with static type
Function." when assigning the value to the function.

Example:
function test()
{
trace(arguments.callee.prop);
}
test.prop = "testing"; // Error

Global.as defines Function as dynamic yet FB produces an error.

This is supposedly possible in AS3 as per:
http://livedocs.macromedia.com/flex/2/docs/1835.html

However, if you try the last example you'll get compiler errors.

Is there a way to add properties to a function? Or is this not supported
in AS3?

--

Derek Vadneau
 



[flexcoders] Functions as objects

2006-12-06 Thread Derek Vadneau
I've tried using the example from the docs where you assign the value
to a property on the function and then use arguments.callee.prop to
get the value, but Flex Builder gives me an error saying "Access of
possibly undefined property prop through a reference with static type
Function." when assigning the value to the function.

Example:
function test()
{
trace(arguments.callee.prop);
}
test.prop = "testing"; // Error

Global.as defines Function as dynamic yet FB produces an error.

This is supposedly possible in AS3 as per:
http://livedocs.macromedia.com/flex/2/docs/1835.html

However, if you try the last example you'll get compiler errors.

Is there a way to add properties to a function? Or is this not supported in AS3?

-- 

Derek Vadneau