[flexcoders] Re: How to stop null on delayed execution.
The problem is that you are instantiating your SimpleExample object and then trying to modify a component of the object before it is created. You would need to move the instantiation of TextInput to the constructor or instantiate it when you create the variable... package { import mx.containers.VBox; import mx.controls.TextInput; import mx.events.FlexEvent; public class SimpleExample extends VBox { private var child:TextInput = new TextInput(); private var _text:String; public function SimpleExample() { super(); addEventListener(FlexEvent.INITIALIZE, init) } private function init(event:FlexEvent):void { addChild(child); } public function get text():String { return _text; } public function set text(text:String):void { this.child.text = text; } } } --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Hi take for for example the following simple example. Its not a real world example but it does show the problem that I wish to avoid. --- MXML (simpletest.mxml) --- ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute xmlns:local=* local:SimpleExample text=hello /local:SimpleExample /mx:Application -- ActionScript SimpleExample.as -- package { import mx.containers.VBox; import mx.controls.TextInput; import mx.events.FlexEvent; public class SimpleExample extends VBox { private var child:TextInput; private var _text:String; public function SimpleExample() { addEventListener(FlexEvent.INITIALIZE, init) } private function init(event:FlexEvent):void { child = new TextInput(); addChild(child); } public function get text():String { return _text; } public function set text(text:String):void { this.child.text = text; } } } If this is run I get a null error at set text. How do I avoid this? Should I just just listen to the property change event on set text? Imagine now that I had multiple different children. Is there a method I can override such as commitProperties so that all this will be done in the same place. I'm sorry if this isn't too clear what I asking. Wesley Acheson.
[flexcoders] Re: How to stop null on delayed execution.
Override createChildren() and add the child there; instead of trying to re-invent the component lifecycle by using INITIALIZE . And yes, commitProperties() would be a good place to set the child's text; from the text property. -TH --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Hi take for for example the following simple example. Its not a real world example but it does show the problem that I wish to avoid. --- MXML (simpletest.mxml) --- ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute xmlns:local=* local:SimpleExample text=hello /local:SimpleExample /mx:Application -- ActionScript SimpleExample.as -- package { import mx.containers.VBox; import mx.controls.TextInput; import mx.events.FlexEvent; public class SimpleExample extends VBox { private var child:TextInput; private var _text:String; public function SimpleExample() { addEventListener(FlexEvent.INITIALIZE, init) } private function init(event:FlexEvent):void { child = new TextInput(); addChild(child); } public function get text():String { return _text; } public function set text(text:String):void { this.child.text = text; } } } If this is run I get a null error at set text. How do I avoid this? Should I just just listen to the property change event on set text? Imagine now that I had multiple different children. Is there a method I can override such as commitProperties so that all this will be done in the same place. I'm sorry if this isn't too clear what I asking. Wesley Acheson.
Re: [flexcoders] Re: How to stop null on delayed execution.
Thanks I thought that always initialising either in the constructor or in the variable declaration was a bit hacky. It is what I've been doing up till now. Is there any refrence for a component (particualy containers) life cycle? Off topic in gmail I autoarchive flex coders emails. Does anyone know of a way to not auto archive treads that I've been involved with? Regards, Wesley Acheson On Tue, Mar 10, 2009 at 5:40 PM, Tim Hoff timh...@aol.com wrote: Override createChildren() and add the child there; instead of trying to re-invent the component lifecycle by using INITIALIZE . And yes, commitProperties() would be a good place to set the child's text; from the text property. -TH --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Hi take for for example the following simple example. Its not a real world example but it does show the problem that I wish to avoid. --- MXML (simpletest.mxml) --- ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute xmlns:local=* local:SimpleExample text=hello /local:SimpleExample /mx:Application -- ActionScript SimpleExample.as -- package { import mx.containers.VBox; import mx.controls.TextInput; import mx.events.FlexEvent; public class SimpleExample extends VBox { private var child:TextInput; private var _text:String; public function SimpleExample() { addEventListener(FlexEvent.INITIALIZE, init) } private function init(event:FlexEvent):void { child = new TextInput(); addChild(child); } public function get text():String { return _text; } public function set text(text:String):void { this.child.text = text; } } } If this is run I get a null error at set text. How do I avoid this? Should I just just listen to the property change event on set text? Imagine now that I had multiple different children. Is there a method I can override such as commitProperties so that all this will be done in the same place. I'm sorry if this isn't too clear what I asking. Wesley Acheson. -- 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
[flexcoders] Re: How to stop null on delayed execution.
Hi Wesley, Controls and Containers all extend UIComponent. For your case, take a look at the code for UIComponent and VBox (F3, with the mouse over a classs name, in FB or Eclipse). Or, just look at any custom component out there; for an example. -TH --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Thanks I thought that always initialising either in the constructor or in the variable declaration was a bit hacky. It is what I've been doing up till now. Is there any refrence for a component (particualy containers) life cycle? Off topic in gmail I autoarchive flex coders emails. Does anyone know of a way to not auto archive treads that I've been involved with? Regards, Wesley Acheson On Tue, Mar 10, 2009 at 5:40 PM, Tim Hoff timh...@... wrote: Override createChildren() and add the child there; instead of trying to re-invent the component lifecycle by using INITIALIZE . And yes, commitProperties() would be a good place to set the child's text; from the text property. -TH --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.acheson@ wrote: Hi take for for example the following simple example. Its not a real world example but it does show the problem that I wish to avoid. --- MXML (simpletest.mxml) --- ?xml version=1.0 encoding=utf-8? mx:Application xmlns:mx=http://www.adobe.com/2006/mxml; layout=absolute xmlns:local=* local:SimpleExample text=hello /local:SimpleExample /mx:Application -- ActionScript SimpleExample.as -- package { import mx.containers.VBox; import mx.controls.TextInput; import mx.events.FlexEvent; public class SimpleExample extends VBox { private var child:TextInput; private var _text:String; public function SimpleExample() { addEventListener(FlexEvent.INITIALIZE, init) } private function init(event:FlexEvent):void { child = new TextInput(); addChild(child); } public function get text():String { return _text; } public function set text(text:String):void { this.child.text = text; } } } If this is run I get a null error at set text. How do I avoid this? Should I just just listen to the property change event on set text? Imagine now that I had multiple different children. Is there a method I can override such as commitProperties so that all this will be done in the same place. I'm sorry if this isn't too clear what I asking. Wesley Acheson. -- 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
[flexcoders] Re: How to stop null on delayed execution.
--- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Is there any refrence for a component (particualy containers) life cycle? This page in the Flex Developer's Guide was very helpful in explaining how to override the Flex component life cycle methods. I also recommend reading the pages before/after this page as well: http://livedocs.adobe.com/flex/3/html/ascomponents_advanced_3.html#209794
[flexcoders] Re: How to stop null on delayed execution.
Why? Standard OOP practice is to initialize variables in the constructor (That's what it's there for). --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Thanks I thought that always initialising either in the constructor or in the variable declaration was a bit hacky.
Re: [flexcoders] Re: How to stop null on delayed execution.
On Tue, Mar 10, 2009 at 6:42 PM, Tim Hoff timh...@aol.com wrote: Hi Wesley, Controls and Containers all extend UIComponent. For your case, take a look at the code for UIComponent and VBox (F3, with the mouse over a classs name, in FB or Eclipse). Or, just look at any custom component out there; for an example. -TH --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Thanks I thought that always initialising either in the constructor or in the variable declaration was a bit hacky. It is what I've been doing up till now. Is there any refrence for a component (particualy containers) life cycle? Off topic in gmail I autoarchive flex coders emails. Does anyone know of a way to not auto archive treads that I've been involved with? Regards, Wesley Acheson Thanks Tim, This is helpfull but I find it difficult to inspect classes in the core libary as. 1. Instance highlightling doesn't work. 2. F3 doesn't take you to a declaration. 3. It doesn't actually tell you when an event is raised or a method is called by looking at the methods as their often called outside the class itself. I'll however make more of an effort to look. Wes
Re: [flexcoders] Re: How to stop null on delayed execution.
On Tue, Mar 10, 2009 at 7:44 PM, sunild99 sunilbd...@gmail.com wrote: This page in the Flex Developer's Guide was very helpful in explaining how to override the Flex component life cycle methods. I also recommend reading the pages before/after this page as well: http://livedocs.adobe.com/flex/3/html/ascomponents_advanced_3.html#209794 Thanks I'll take a look. Wes
Re: [flexcoders] Re: How to stop null on delayed execution.
Because of a visual components life cycle mainly. If I was to write an application in actionscript (asside from the root mxml file - I don't think you can do that in AS) all visual components would be initialised immediatly. Lazy loading is also used quite commonly as an OOP pattern. Also constructor initialisation falls out of grace, (I think) with stuff like spring in java as it doesn't allow well for dependency injection. Finally Its just nice for people using your custom components if they act like other components. It means less to learn. These are just opinions though I have mostly been writing my code in the same way as you gave in the example. i.e. private var someVar:someClass = new someClass(); Thanks for your help too though. I did change my real class *not* the simplified example to do that when I got your reply as I needed to get it working quickly. On Tue, Mar 10, 2009 at 8:05 PM, valdhor valdhorli...@embarqmail.comwrote: Why? Standard OOP practice is to initialize variables in the constructor (That's what it's there for). --- In flexcoders@yahoogroups.com, Wesley Acheson wesley.ache...@... wrote: Thanks I thought that always initialising either in the constructor or in the variable declaration was a bit hacky. -- 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