1 Reply Latest reply on Apr 22, 2010 9:51 AM by Shongrunden

    Can't add a sprite to the stage

    SiHoop Level 1

      I want to add a component to the stage. Here's the componenet: MainPanel.mxml

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"   backgroundColor="#C72828"  
          borderStyle="none" creationComplete="init()">
      <mx:Script>
        <![CDATA[
      public function init():void{
          this.width=100;
          this.height=100;
      }
        ]]>
      </mx:Script>
           
      </mx:Panel>

       

       

      I can add it to an HBox and make it appear. I can add it to a UIComponent and make it appear. But I cannot add it to a Sprite, then add the Sprite to the UIComponent and make it appear (see commented lines below). Why am I having such a tough time understanding how to add the sprite to the stage? Should I be using a different type of container?

       

      Any advice would be much appreciated. I like working with the Sprite as it allows me to do so many other things.

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"   applicationComplete="init()">
          <mx:Script>
        <![CDATA[
      private var sprite:Sprite=new Sprite;
      public function init():void{
          for(var i:int=0; i<5;i++){
              var panel1:MainPanel=new MainPanel;
              panel1.x=i*120;
              panel1.y=100
              //hbox.addChild(panel1)
              //uic.addChild(panel1)
              //sprite.addChild(panel1)
          }
          uic.addChild(sprite)
      }
        ]]>
      </mx:Script>
            <mx:UIComponent id="uic"/>
            <mx:HBox id="hbox" />
      </mx:Application>