Search the web
Sign In
New User? Sign Up
flexcoders · RIA Development with Adobe Flex

Group Information

  • Members: 9160
  • Category: Development
  • Founded: Mar 17, 2004
  • Language: English
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Real people. Real stories. See how Yahoo! Groups impacts members worldwide.

Messages

  Messages Help
Advanced
Functions as objects   Message List  
Reply Message #58388 of 164928 |
Re: [flexcoders] Functions as objects

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 = member.@name;
                        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 < leadedsnow@...> 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 < anatole.tartakovsky@... > 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




Fri Dec 8, 2006 6:00 pm

johny_bravo_78
Offline Offline
Send Email Send Email

Message #58388 of 164928 |
Expand Messages Author Sort by Date

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...
Derek Vadneau
leadedsnow Offline Send Email
Dec 6, 2006
5:44 pm

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...
Clint Modien
johny_bravo_78 Offline Send Email
Dec 8, 2006
6:03 am

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...
Derek Vadneau
leadedsnow Offline Send Email
Dec 8, 2006
4:02 pm

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...
Anatole Tartakovsky
anatolet Offline Send Email
Dec 8, 2006
4:10 pm

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...
Derek Vadneau
leadedsnow Offline Send Email
Dec 8, 2006
4:44 pm

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...
Clint Modien
johny_bravo_78 Offline Send Email
Dec 8, 2006
6:01 pm

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...
Anatole Tartakovsky
anatolet Offline Send Email
Dec 8, 2006
6:56 pm

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 ...
Derek Vadneau
leadedsnow Offline Send Email
Dec 8, 2006
7:18 pm

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....
Francis Cheng
xlcheng Offline Send Email
Dec 8, 2006
6:48 pm

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 ...
Anatole Tartakovsky
anatolet Offline Send Email
Dec 8, 2006
9:29 pm
Advanced

Copyright © 2010 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines NEW - Help