3 Replies Latest reply on Mar 27, 2011 1:54 PM by Lee Burrows

    Display list question

    SiHoop Level 1

      I've never really understood how to add a class instance to the display list when the class has no visual interface. I always add the instance to a UIComponent, but it seems that there must be a better way to do this.Can anyone tell me if there is a better way, or if this is actually the correct way to do it?

      Thank you.

       

      Here's an example illustrating what I do:

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
          <mx:Script>
              <![CDATA[
          private function init():void{
              var ball:Ball=new Ball()
              container.addChild(ball)
          }
              ]]>
          </mx:Script>
          <mx:UIComponent id="container" />
      </mx:Application>

       

       

      Ball.as

       

      package {
          import flash.display.Shape;
          public class Ball extends Shape{
              public function Ball(){
                  graphics.beginFill(0xff0000);
                  graphics.drawCircle(0,0,15);
                  graphics.endFill();
              }
          }
      }

        • 1. Re: Display list question
          pauland Level 4

          I don't really see what the issue is. Using addChild() is the way to add something to the display list and that's what you are doing, so what else is there to say?

           

          It wasn't necessary to fabricate the container, unless you really wanted to.

          • 2. Re: Display list question
            Lee Burrows Level 4

             

            hi

             

            if your visual class doesn't extend UIComponent (like Ball.as) then it wont have any of the flex stuff baked in - so it needs to be wrapped in a UIComponent (or something that extends UIComponent) for flex to be able to manage it (ie: layout)

             

            rather than Ball extending Shape, it should extend UIComponent

             

            i only use flex 4 now so i cant be sure, but i believe that you can not add non-UIComponents to the root application display list.

             

            • 3. Re: Display list question
              pauland Level 4

              Ah! Absolutely right about UIComponent. Spending too much time with flash..