2 Replies Latest reply on Nov 3, 2009 6:53 AM by serj_is

    UIComponent.addChild makes items to be visible outside of area

    serj_is

      Hello,

      I am new with flex and actionscript, so...

       

      I want to add some sprites inside of container (UIComponent) and this container to act like a "clip area" - limit painting only to items inside of bounds. I want to use this code for custom horizonal scrollingcontainer.PNG

      thanks

       

       

      This is code:

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

       

      package

       

       

      import flash.display.Sprite;

       

       

       

      import mx.core.*;

       

       

       

      import util.*;

       

       

       

      {

       

           public class HorizontalImageContainer extends UIComponent{

       

       

                public var bgColor:int = 0xFFCCFF;

       

       

       

                private var itemWidth:int = 62;

       

       

                private var itemHeight: int = 62;

       

       

                private var innerSpace:int = 8;

       

       

                private var bgColors:Array = [0xFF0000,0x00FF00,0x0000FF];

       

       

       

                private var items:Array = new Array();

       

       

               

                public function HorizontalImageContainer(width:Number=500,height:Number=80,bgColor:int=0xFFCCFF){

       

       

                     super();

       

       

       

                     this.bgColor = bgColor;

       

       

                     this.width = width;

       

       

                     this.height = height;

       

       

                     this.graphics.clear();

       

       

                     createItemsForTesting();

       

       

                     this.graphics.lineStyle(1, 0x000000, 0.5, true);

       

       

                     this.graphics.drawRoundRect(0, 0, width-1, height-1, 7, 7);

                }

       

       

       

       

                private function createItemsForTesting():void{

       

       

                     for(var i:int=0;i<20;i++){

       

       

                          var x: int = i*(itemWidth+innerSpace);

       

       

                          var y: int = 0;

       

       

                          var bgColor:int = bgColors[i%3];

       

       

                          var text:String = (i+1)+"";

       

       

                          var item:Sprite = new Sprite();

                          item.x = x;

                          item.y = y;

                          item.graphics.lineStyle(1,0xFFCCFF, 0.5,

      true);

                          item.graphics.beginFill(0xFFCCFF, 1);

                          item.graphics.drawRoundRect(0, 0, itemWidth-1, itemHeight-1, 7, 7);

       

                          items.push(item);

       

       

                          //if(i>itemsInRow-1){

       

       

       

                          // item.visible = false;

       

       

       

                          //}

       

       

       

                          this.addChild(item);

                     }

                 }

           }

       

      }