3 Replies Latest reply on Feb 27, 2008 10:11 PM by VarioPegged

    rawchildren

    SiHoop Level 1
      Whenever I want to display an object from within an <mx:Script> tag I end up using a statement such as:
      this.rawChildren.addChild(someObject)

      I don't understand why I have to use rawChildren and cannot find a good description of its purpose. Is it necessary or is it a work around for something simpler? When does it have to be included, and when can I use addChild?
      Thank you!



        • 1. Re: rawchildren
          m_hartnett Level 3
          I am not sure what you mean but here is some sample code that may help. This simply uses the addChild method to add an object to either the application or some container (a vbox in this case)

          <?xml version="1.0" encoding="utf-8"?>
          <!-- Tree control example. -->
          <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml">

          <mx:Script>
          <![CDATA[
          import mx.controls.Button;
          private function addToApp(e:Event) : void {
          var btn : Button = new Button();
          btn.label = "button added to app";
          this.addChild(btn);
          }

          private function addToVBox(e:Event) : void {
          var btn1 : Button = new Button();
          btn1.label = "button added to vbox";
          vbox.addChild(btn1);
          }


          ]]>
          </mx:Script>
          <mx:Button x="10" y="10" label="Add to App" click="addToApp(event)"/>
          <mx:Button x="145" y="10" label="Add to VBox" click="addToVBox(event)"/>
          <mx:VBox id="vbox" x="10" y="56" height="319" width="241" backgroundColor="#ffffff">
          </mx:VBox>

          </mx:Application>
          • 2. Re: rawchildren
            SiHoop Level 1
            Ok, here's an example of what I'm talking about: Take away the rawChildren and it fails. Why does this happen?

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="loginInit()">
            <mx:Script>
            <![CDATA[
            private function loginInit():void{
            var child:Shape = new Shape();
            child.graphics.beginFill(0x000000);
            child.graphics.drawRect(100, 100, 100, 100);
            child.graphics.endFill();
            this.rawChildren.addChild(child);
            }
            ]]>
            </mx:Script>
            </mx:Application>
            • 3. Re: rawchildren
              VarioPegged Level 2
              I'll chime in here...
              A child can only be added to a container (which is what <mx:Application> is) using this.addChild(child) if the child implements IUIComponent.

              So, to do what you want to do without using rawChildren you could create a simple class that extends UIComponent (which implements IUIComponent)...

              package
              {
              import mx.core.UIComponent;
              import flash.display.Shape;
              public class ShapeClass extends UIComponent
              {
              public function ShapeClass()
              {
              super();
              drawShape();
              }
              private function drawShape():void
              {
              var child:Shape = new Shape();
              child.graphics.beginFill(0x000000);
              child.graphics.drawRect(100, 100, 100, 100);
              child.graphics.endFill();
              addChild(child);
              }
              }
              }

              Then your Application would be something like:
              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" creationComplete="loginInit()" horizontalAlign="left" >
              <mx:Script>
              <![CDATA[
              import ShapeClass;

              private function loginInit():void{
              var sc:ShapeClass = new ShapeClass();
              addChild(sc);
              }

              ]]>
              </mx:Script>
              </mx:Application>

              TS