7 Replies Latest reply on Aug 21, 2009 11:59 AM by Flex harUI

    Display list question

    SiHoop Level 1

      I'm using a Canvas which is a Container, but I'm having to use a UIContainer to display a Shape (i.e. goalBox) that I have drawn: mainDisplay.addChild(goalBox)

       

      Why can I not add goalBox to the Canvas like this?: this.addChild(goalBox)

      This seems like a very basic question, but I don't get it.

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Canvas xmlns:custom="components.*" xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="drawStudentGoalLine()"  verticalScrollPolicy="off">
      <mx:Script>
          <![CDATA[
      import mx.core.UIComponent;
      import flash.display.*
      private    var goalBox:Shape = new Shape();
      public function drawStudentGoalLine():void{
          var lineColor:uint=0xbbc69b;   
          goalBox.graphics.lineStyle(0, lineColor);
          goalBox.graphics.beginFill(lineColor, 1)
          goalBox.graphics.drawRect(0, 30, 74, 10);
          mainDisplay.addChild(goalBox)
      }
          ]]>
      </mx:Script>
      <mx:UIComponent id="mainDisplay" />
      <mx:TextArea text="Text"  height="30" width="75"/>
      </mx:Canvas>