17 Replies Latest reply on Dec 18, 2008 10:57 AM by Newsgroup_User

    Does creationComplete count for nested components as well?

    john isaacks Level 1
      I have a custom component that extends VBox with several nested components. One of these nested components is a TextArea .

      I try to set the text of the textfield and I get an error telling me its a null object. But I call this AFTER creation complete of my component. So I am guessing the creationComplete only dispatches after the component itself is created and not all of its children. So how can I tell when all of the components children are created?

      Thanks!!!
        • 1. Re: Does creationComplete count for nested components as well?
          Level 7

          "john isaacks" <webforumsuser@macromedia.com> wrote in message
          news:gi8kom$ghc$1@forums.macromedia.com...
          >I have a custom component that extends VBox with several nested components.
          >One
          > of these nested components is a TextArea .
          >
          > I try to set the text of the textfield and I get an error telling me its a
          > null object. But I call this AFTER creation complete of my component. So I
          > am
          > guessing the creationComplete only dispatches after the component itself
          > is
          > created and not all of its children. So how can I tell when all of the
          > components children are created?

          What's the code that is building the nested children?

          What's the line of code that sets the Textarea's text?

          Why isn't the custom component in charge of setting its children's
          properties?


          • 2. Re: Does creationComplete count for nested components as well?
            john isaacks Level 1
            the component is in charge, the textarea is nested using mxml so it should be there right away. there is a setter function in the component that onces set it puts text into the textarea. I don't call the setter function until after the components creationComplete. I also am using a trace to tell weather the the function is complete and weather the textarea is null...and it outputs true:null (meaning creationComplete is true but the nested textarea is null) I attached the code for the component accept removed irrelevant parts.

            Thanks!!!
            • 3. Re: Does creationComplete count for nested components as well?
              ntsiii Level 3
              Properties on components, whether public vars or setter functions are set BEFORE creationComplete.

              Tracy
              • 4. Re: Does creationComplete count for nested components as well?
                Level 7

                "john isaacks" <webforumsuser@macromedia.com> wrote in message
                news:gi8p1f$lpk$1@forums.macromedia.com...
                > the component is in charge, the textarea is nested using mxml so it should
                > be
                > there right away. there is a setter function in the component that onces
                > set it
                > puts text into the textarea. I don't call the setter function until after
                > the
                > components creationComplete. I also am using a trace to tell weather the
                > the
                > function is complete and weather the textarea is null...and it outputs
                > true:null (meaning creationComplete is true but the nested textarea is
                > null) I
                > attached the code for the component accept removed irrelevant parts.

                Try calling it on creationComplete of the VBox that contains the TextArea,
                or even the TextArea itself. I think once the VBox containing the ta is
                added, that's the only thing the parent cares about in determining whether
                it is complete.

                You might also want to consider this alternate syntax:

                <?xml version="1.0" encoding="utf-8"?>
                <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml"
                creationComplete="onComplete(event)">
                <mx:Script>
                <![CDATA[
                import mx.controls.TextArea;

                private var _complete:Boolean;
                private var _stoneCount:uint;
                private var _selectedStyle:String;
                [Bindable]
                private var _stylesXML:XML=
                <root style_code="dummy code">
                </root>;



                public function set stylesXML(xml:XML):void
                {
                trace(_complete+":"+ta2); // returns true:null
                _stylesXML = xml;

                //probly still need to fix code below

                if(ring_image)
                {
                ring_image.source =
                ' http://www.kranichs.com/mothers_rings/MothersRingsImages/'+xml.style.(@style_co
                de == _selectedStyle).ring.ring_style[0].@image;
                }
                }


                private function onComplete (e:Event):void
                {
                _complete = true;
                }

                ]]>
                </mx:Script>
                <mx:VBox>
                <mx:Panel id="leftPane" width="200" height="480">
                <mx:Accordion width="100%">
                <mx:VBox label="Entire XML">
                <mx:TextArea id="ta1" width="177" height="300" text="{_stylesXML}"/>
                </mx:VBox>
                <mx:VBox label="Style XML">
                <mx:TextArea id="ta2" width="177" height="300"
                text="{stylesXML.(attribute('style_code') == _selectedStyle)}"/>
                </mx:VBox>
                </mx:Accordion>
                </mx:Panel>
                </mx:VBox>

                </mx:HBox>

                I'm not seeing where _selectedStyle is being set, so I might have messed up
                in the way I used it above.

                Personally, though, I think you should just set a property on the component
                and let the component handle the timing in accordance with its life cycle,
                as Tracy said. Look at the docs for "commitProperties."

                HTH;

                Amy


                • 5. Re: Does creationComplete count for nested components as well?
                  john isaacks Level 1
                  "Properties on components, whether public vars or setter functions are set BEFORE creationComplete."
                  I believe this is only when you set them with mxml right? I am not.

                  I am creating this component like so:
                  <local:_Customizer id="customizer" creationComplete="{initCustomizer(event)}"/>

                  then these functions set the properties AFTER creation complete:

                  private function initCustomizer (e:Event):void
                  {
                  customizer.addEventListener(Event.ADDED_TO_STAGE, setupCustomizer);
                  setupCustomizer();
                  }

                  private function setupCustomizer (e:Event = null):void
                  {
                  customizer.stoneCount = Number(_stoneCount);
                  customizer.selectedStyle = _selectedStyle
                  customizer.stylesXML = _stylesXML;
                  }


                  Also Amy you said you could not see how I was setting _selectedStyle I didn't post it because I thought it was irrelevant. Here it is:

                  [Bindable]
                  public function get selectedStyle():String
                  {
                  return _selectedStyle;
                  }
                  public function set selectedStyle(s:String):void
                  {
                  _selectedStyle = s;
                  style_label.text = "Style: "+_selectedStyle;
                  }


                  Also I am just putting the data in text fields for now so I can verify that everything is receiving the right data.

                  I'm still confused on how I can pass a value to a component and that component pass the value to its children without worrying whether they exist yet. I am new to flex but I have been programming actionscript in flash for quite some time and I have never had to deal with this, it is very new to me.

                  Thanks!
                  • 6. Re: Does creationComplete count for nested components as well?
                    Level 7

                    "john isaacks" <webforumsuser@macromedia.com> wrote in message
                    news:gib2c2$l4u$1@forums.macromedia.com...
                    > "Properties on components, whether public vars or setter functions are set
                    > BEFORE creationComplete."
                    > I believe this is only when you set them with mxml right? I am not.
                    >
                    > I am creating this component like so:
                    > <local:_Customizer id="customizer"
                    > creationComplete="{initCustomizer(event)}"/>
                    >
                    > then these functions set the properties AFTER creation complete:
                    >
                    > private function initCustomizer (e:Event):void
                    > {
                    > customizer.addEventListener(Event.ADDED_TO_STAGE, setupCustomizer);
                    > setupCustomizer();
                    > }
                    >
                    > private function setupCustomizer (e:Event = null):void
                    > {
                    > customizer.stoneCount = Number(_stoneCount);
                    > customizer.selectedStyle = _selectedStyle
                    > customizer.stylesXML = _stylesXML;
                    > }
                    >
                    >
                    > Also Amy you said you could not see how I was setting _selectedStyle I
                    > didn't
                    > post it because I thought it was irrelevant. Here it is:
                    >
                    > [Bindable]
                    > public function get selectedStyle():String
                    > {
                    > return _selectedStyle;
                    > }
                    > public function set selectedStyle(s:String):void
                    > {
                    > _selectedStyle = s;
                    > style_label.text = "Style: "+_selectedStyle;
                    > }
                    >
                    >
                    > Also I am just putting the data in text fields for now so I can verify
                    > that
                    > everything is receiving the right data.
                    >
                    > I'm still confused on how I can pass a value to a component and that
                    > component
                    > pass the value to its children without worrying whether they exist yet. I
                    > am
                    > new to flex but I have been programming actionscript in flash for quite
                    > some
                    > time and I have never had to deal with this, it is very new to me.

                    Please post enough code where I can recreate your project without starting
                    from scratch, and I'll put something together for you. If you could post a
                    project somewhere that I could just import that would be even better.

                    -Amy


                    • 7. Re: Does creationComplete count for nested components as well?
                      john isaacks Level 1
                      Thank you very much Amy that is a very generous.

                      I put the entire project in a zip you can download here:
                      www.kra nichs.com/temp/flex.zip

                      The main application that embeds the component is _MothersRings.mxml and the component is _Customizer.mxml

                      Thanks again.
                      • 8. Re: Does creationComplete count for nested components as well?
                        Level 7

                        "john isaacks" <webforumsuser@macromedia.com> wrote in message
                        news:giba10$132$1@forums.macromedia.com...
                        > Thank you very much Amy that is a very generous.
                        >
                        > I put the entire project in a zip you can download here:
                        > www.kra nichs.com/temp/flex.zip
                        >
                        > The main application that embeds the component is _MothersRings.mxml and
                        > the
                        > component is _Customizer.mxml
                        >
                        > Thanks again.

                        That url didn't work.


                        • 9. Re: Does creationComplete count for nested components as well?
                          john isaacks Level 1
                          You have to remove the "space" in the domain name I added so it wouldn't be indexed by search engines.

                          Thanks!
                          • 10. Re: Does creationComplete count for nested components as well?
                            Level 7

                            "john isaacks" <webforumsuser@macromedia.com> wrote in message
                            news:gibi9o$b64$1@forums.macromedia.com...
                            > You have to remove the "space" in the domain name I added so it wouldn't
                            > be indexed by search engines.
                            >
                            > Thanks!

                            I tried that already :-). Got it to work by also adding http at the front.


                            • 11. Re: Does creationComplete count for nested components as well?
                              Level 7

                              "john isaacks" <webforumsuser@macromedia.com> wrote in message
                              news:gibi9o$b64$1@forums.macromedia.com...
                              > You have to remove the "space" in the domain name I added so it wouldn't
                              > be indexed by search engines.
                              >
                              > Thanks!

                              It's not really obvious to me what I'm supposed to do to get it into the
                              state where the component you're talking about would be created.


                              • 12. Re: Does creationComplete count for nested components as well?
                                john isaacks Level 1
                                I am sorry about that.

                                The fastest way is to add this fragment to the URL pathToProject/_MothersRings.html#Customize/4/style 83

                                Also to get navigate there, in the first state click the "go" button then in the next state click any TileList item, then you will be taken to the third state which is the state that adds the _Customizer component.

                                THANKS
                                • 13. Re: Does creationComplete count for nested components as well?
                                  Level 7

                                  "john isaacks" <webforumsuser@macromedia.com> wrote in message
                                  news:gidn1f$5is$1@forums.macromedia.com...
                                  >I am sorry about that.
                                  >
                                  > The fastest way is to add this fragment to the URL
                                  > pathToProject/_MothersRings.html#Customize/4/style 83
                                  >
                                  > Also to get navigate there, in the first state click the "go" button then
                                  > in
                                  > the next state click any TileList item, then you will be taken to the
                                  > third
                                  > state which is the state that adds the _Customizer component.

                                  There was no go button visible. I'll try the other and see if that works.


                                  • 14. Re: Does creationComplete count for nested components as well?
                                    Level 7

                                    "john isaacks" <webforumsuser@macromedia.com> wrote in message
                                    news:gidn1f$5is$1@forums.macromedia.com...
                                    >I am sorry about that.
                                    >
                                    > The fastest way is to add this fragment to the URL
                                    > pathToProject/_MothersRings.html#Customize/4/style 83
                                    >
                                    > Also to get navigate there, in the first state click the "go" button then
                                    > in
                                    > the next state click any TileList item, then you will be taken to the
                                    > third
                                    > state which is the state that adds the _Customizer component.
                                    >
                                    > THANKS

                                    I'd suggest you import the project you sent me as a new porject and see what
                                    it looks like to me. I suspect the fact you didn't include the libs
                                    directory is at least part of the problem.


                                    • 15. Re: Does creationComplete count for nested components as well?
                                      Level 7

                                      "Amy Blankenship" <amySpamFilter@magnolia_pleaseNOspam_multimedia.com> wrote
                                      in message news:gidrtl$bhf$1@forums.macromedia.com...
                                      >
                                      > "john isaacks" <webforumsuser@macromedia.com> wrote in message
                                      > news:gidn1f$5is$1@forums.macromedia.com...
                                      >>I am sorry about that.
                                      >>
                                      >> The fastest way is to add this fragment to the URL
                                      >> pathToProject/_MothersRings.html#Customize/4/style 83
                                      >>
                                      >> Also to get navigate there, in the first state click the "go" button then
                                      >> in
                                      >> the next state click any TileList item, then you will be taken to the
                                      >> third
                                      >> state which is the state that adds the _Customizer component.
                                      >>
                                      >> THANKS
                                      >
                                      > I'd suggest you import the project you sent me as a new porject and see
                                      > what it looks like to me. I suspect the fact you didn't include the libs
                                      > directory is at least part of the problem.

                                      OK, I got this to work well enough to get into the logic you're talking
                                      about.

                                      And, big oops, I somehow missed that the problem text area was in an
                                      Accordion.
                                      http://www.magnoliamultimedia.com/flex_examples/Amys_Flex_FAQ.pdf Q5

                                      Here's how I've changed your code in sort of a quick and dirty way. I don't
                                      like using bindings this way myself, but on the surface they're easier to
                                      understand than overriding commitProperties. Note that if you do it this
                                      way you don't need to wait for the complete event before setting the
                                      properties. As soon as they're available they'll just go where they need to
                                      go.

                                      <?xml version="1.0" encoding="utf-8"?>

                                      <mx:HBox xmlns:mx=" http://www.adobe.com/2006/mxml"
                                      creationComplete="onComplete(event)">

                                      <mx:Script>

                                      <![CDATA[

                                      import mx.controls.TextArea;


                                      private var _complete:Boolean;

                                      private var _stoneCount:uint;

                                      private var _selectedStyle:String;

                                      [Bindable]

                                      private var _stylesXML:XML = <root style_code="dummy code"/>;


                                      [Bindable]

                                      public function get stoneCount():uint

                                      {

                                      return _stoneCount;

                                      }

                                      public function set stoneCount(n:uint):void

                                      {

                                      _stoneCount = n;

                                      //trace(stone_label);

                                      stone_label.text = "Stones: "+_stoneCount;

                                      }


                                      [Bindable]

                                      public function get selectedStyle():String

                                      {

                                      return _selectedStyle;

                                      }

                                      public function set selectedStyle(s:String):void

                                      {

                                      _selectedStyle = s;

                                      style_label.text = "Style: "+_selectedStyle;

                                      }


                                      public function set stylesXML(xml:XML):void

                                      {

                                      trace(_complete+":"+ta2);

                                      _stylesXML = xml;


                                      /* if(ta1){

                                      ta1.text = xml;

                                      }

                                      if(ta2){

                                      //ta2.text = xml.style.(@style_code == _selectedStyle);

                                      }


                                      if(ring_image)

                                      {

                                      ring_image.source =
                                      ' http://www.kranichs.com/mothers_rings/MothersRingsImages/'+xml.style.(@style_code
                                      == _selectedStyle).ring.ring_style[0].@image;

                                      }*/


                                      }



                                      private function onComplete (e:Event):void

                                      {

                                      _complete = true;

                                      }


                                      ]]>

                                      </mx:Script>

                                      <mx:VBox>

                                      <mx:Panel id="leftPane" width="200" height="480">

                                      <mx:Accordion width="100%">

                                      <mx:VBox label="Entire XML">

                                      <mx:TextArea id="ta1" width="177" height="300"
                                      text="{_stylesXML?_stylesXML:'sdfsdfsdf'}"/>

                                      </mx:VBox>

                                      <mx:VBox label="Style XML">

                                      <mx:TextArea id="ta2" width="177" height="300"
                                      text="{_stylesXML.(attribute('style_code') == selectedStyle)}"/>

                                      </mx:VBox>

                                      </mx:Accordion>

                                      </mx:Panel>

                                      </mx:VBox>

                                      <mx:VBox>

                                      <mx:Panel width="350" height="480">

                                      <mx:Label id="stone_label"/>

                                      <mx:Label id="style_label"/>

                                      <mx:Image id="ring_image"
                                      source="{' http://www.kranichs.com/mothers_rings/MothersRingsImages/'+_stylesXML.style.(@style_code
                                      == _selectedStyle).ring.ring_style[0].@image}"/>

                                      </mx:Panel>

                                      </mx:VBox>

                                      <mx:VBox>

                                      <mx:Panel width="200" height="480">

                                      <mx:Label text="Panel 3"/>

                                      </mx:Panel>

                                      </mx:VBox>

                                      </mx:HBox>


                                      HTH;

                                      Amy


                                      • 17. Re: Does creationComplete count for nested components as well?
                                        Level 7

                                        "john isaacks" <webforumsuser@macromedia.com> wrote in message
                                        news:gie1fe$i7m$1@forums.macromedia.com...
                                        > Thank you very much!

                                        You're welcome ;-)