Re: [flexcoders]How do I know if a class is on the Application?
I mean like this: ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute managers:MyBadPracticesClass / /mx:Application If it was a display object all the suggestions would work but it extends EventDispatcher and manages states, etc. The problem was that the id was not getting set. It also was not enumerated when I looped through the application. What I had to do was implement the IMXMLObject interface. This notified the application to call an initialized function that passed in a reference to the document (application) and id of the instance both of which are not present when you extend EventDispatcher or Object. I did this so that I could make it behave like a singleton. But it's all working now in bad practices land. :P Paul, this is a reincarnation of the other question (posted before it was solved). On Mon, Jan 12, 2009 at 12:52 AM, Haykel BEN JEMIA hayke...@gmail.comwrote: I have to ask again: What do you mean with on the application? I you mean added to some display list, then it must be a subclass of DisplayObject. Or perhaps you can tell what you want to do exactly. Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Sun, Jan 11, 2009 at 5:42 AM, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: It's a manager class that extends EventDispatcher. On Sat, Jan 10, 2009 at 12:17 AM, Haykel BEN JEMIA hayke...@gmail.comwrote: What do you mean with on the application? If you mean added to the stage, then you can't find this out in the constructor. Make sure your class is a subclass of DisplayObject and listen to the added or addedToStage events. Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Sat, Jan 10, 2009 at 7:06 AM, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? dorkie dork from dorktown™
Re: [flexcoders]How do I know if a class is on the Application?
On 1/10/09, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? By Application I assume the Flex application (instance of mx.core.Application). The only way to do this is to walk the parent chain (parent.parent.parent) until you come across an Application instance, or null. inApplication = false; p = this.parent; while (p != null) { if (p is Application) { inApplication = true; break; } p = p.parent; } Your loop will never run, however, since parent will always be null in the constructor. Note that checking for Application is different from checking for stage. The Application may not have been added to the stage when you're doing this check (even if not in the constructor). So if you want to check if you're on the stage yet, just check for the stage property. onStage = (stage != null); Manish -- http://manishjethani.com
Re: [flexcoders]How do I know if a class is on the Application?
- Original Message - From: dorkie dork from dorktown To: flexcoders@yahoogroups.com Sent: Saturday, January 10, 2009 6:06 AM Subject: [flexcoders]How do I know if a class is on the Application? I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? Is this just another incarnation of your mxml singleton question? dorkie dork from dorktown™
Re: [flexcoders]How do I know if a class is on the Application?
To reference the application object inside another object (either UI or otherwise) just define a variable to reference Applicaton.application; Note that this returns an object - not an instance of Application per se. One interesting note is that singletons can be instantiated through using a check in the following manner... var _x:Object = Application.application; if (_x[mySingleton] == null) { _x[mySingleton] = new SingletonClass(); } return _x[mySingleton] as SingletonClass; Maybe that helps someone ;) Samuel On Jan 11, 2009, at 1:32 PM, Manish Jethani wrote: On 1/10/09, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? By Application I assume the Flex application (instance of mx.core.Application). The only way to do this is to walk the parent chain (parent.parent.parent) until you come across an Application instance, or null. inApplication = false; p = this.parent; while (p != null) { if (p is Application) { inApplication = true; break; } p = p.parent; } Your loop will never run, however, since parent will always be null in the constructor. Note that checking for Application is different from checking for stage. The Application may not have been added to the stage when you're doing this check (even if not in the constructor). So if you want to check if you're on the stage yet, just check for the stage property. onStage = (stage != null); Manish -- http://manishjethani.com
Re: [flexcoders]How do I know if a class is on the Application?
I have to ask again: What do you mean with on the application? I you mean added to some display list, then it must be a subclass of DisplayObject. Or perhaps you can tell what you want to do exactly. Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Sun, Jan 11, 2009 at 5:42 AM, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: It's a manager class that extends EventDispatcher. On Sat, Jan 10, 2009 at 12:17 AM, Haykel BEN JEMIA hayke...@gmail.comwrote: What do you mean with on the application? If you mean added to the stage, then you can't find this out in the constructor. Make sure your class is a subclass of DisplayObject and listen to the added or addedToStage events. Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Sat, Jan 10, 2009 at 7:06 AM, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? dorkie dork from dorktown™
Re: [flexcoders]How do I know if a class is on the Application?
It's a manager class that extends EventDispatcher. On Sat, Jan 10, 2009 at 12:17 AM, Haykel BEN JEMIA hayke...@gmail.comwrote: What do you mean with on the application? If you mean added to the stage, then you can't find this out in the constructor. Make sure your class is a subclass of DisplayObject and listen to the added or addedToStage events. Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Sat, Jan 10, 2009 at 7:06 AM, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? dorkie dork from dorktown™
Re: [flexcoders]How do I know if a class is on the Application?
You could probably look by using the Application.application instance to access the Application object, then look through the children using numChildren and getChildAt in a loop. I have to ask though, why? It doesn't sound like a neat solution - maybe you could pass in the Application instance when creating it, e.g. managers:MyClass app={this} / 2009/1/10 dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com: I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? dorkie dork from dorktown™ -- Flexcoders Mailing List FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt Alternative FAQ location: https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups Links * To visit your group on the web, go to: http://groups.yahoo.com/group/flexcoders/ * Your email settings: Individual Email | Traditional * To change settings online go to: http://groups.yahoo.com/group/flexcoders/join (Yahoo! ID required) * To change settings via email: mailto:flexcoders-dig...@yahoogroups.com mailto:flexcoders-fullfeatu...@yahoogroups.com * To unsubscribe from this group, send an email to: flexcoders-unsubscr...@yahoogroups.com * Your use of Yahoo! Groups is subject to: http://docs.yahoo.com/info/terms/
Re: [flexcoders]How do I know if a class is on the Application?
What do you mean with on the application? If you mean added to the stage, then you can't find this out in the constructor. Make sure your class is a subclass of DisplayObject and listen to the added or addedToStage events. Haykel Ben Jemia Allmas Web RIA Development http://www.allmas-tn.com On Sat, Jan 10, 2009 at 7:06 AM, dorkie dork from dorktown dorkiedorkfromdorkt...@gmail.com wrote: I have a class on the application like this: managers:MyClass / How do I find out inside that class in the constructor if that class is on the Application? dorkie dork from dorktown™