0 Replies Latest reply on May 31, 2008 10:36 AM by brmcc

    Adding a CheckBox to a Sprite

    brmcc
      I would like to be able to add a CheckBox to a Sprite, or failing that, a UIComponent. However *if* this is possible, I must be doing something wrong as illustrated in the code below. Adding the CheckBox to the Sprite produces no visible results. Also note that when adding a CheckBox to a UIComponent, its height/width must be set explicitly in order for it to render properly.

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
      layout="absolute"
      creationComplete="initApp()">

      <mx:Script>
      <![CDATA[
      import mx.controls.CheckBox;

      public function initApp():void
      {
      // 1. This works as expected
      var inPanel: CheckBox = new CheckBox();
      inPanel.label = "inPanel";
      thePanel.addChild(inPanel);

      // 2. This works, but if height/width not explicitly
      // set then the label is displayed only as a tooltip
      var inUIC: CheckBox = new CheckBox();
      inUIC.label = "inUIC";
      inUIC.x = 80;
      inUIC.height = 40; // If not set, no label
      inUIC.width = 80; // ditto
      theUIC.addChild(inUIC);

      // Add a Sprite to parent a checkbox
      var theSprite: Sprite = new Sprite();
      theSprite.graphics.lineStyle(0,0x000000);
      theSprite.graphics.drawRect(0,0,100,100);
      theSprite.x = 160;
      theUIC.addChild(theSprite);

      // 3. This doesn't work, no compile or runtime
      // error -- it just has no runtime effect
      var inSprite: CheckBox = new CheckBox();
      inSprite.label = "inSprite";
      theSprite.addChild(inSprite);
      }
      ]]>
      </mx:Script>

      <mx:Panel layout="absolute" title="Add Controls" id="thePanel">
      <mx:UIComponent width="300" height="300" id="theUIC"/>
      </mx:Panel>
      </mx:Application>