开发者

Delete group containers in runtime in flex

i am trying to make a some groups within a predefined group at run time. i can make groups, the code is working fine. Now i have added two buttons in each group which is created in run time. now the problem is one of the button is x . the property of button should be when i click on it it should delete the very specific group in which it is built. please check out the code and tell me what additions should i make.

            public var n:Number = 0;

        protected function remover (event:MouseEvent):void
        {
        }

        protected function settings(g:Group):void
        {
            ((DisplayObject)(g)).width = "200";
            ((DisplayObject)(g)).height = "140";
            ((DisplayObject)(g)).x = "200" ;
            ((DisplayObject)(g)).y = "200";
            var s:String;

            s = "NewGroup"+ "X"+ n.toString;
            var mybutton1:Button = new Button();
            mybutton1.id = s;
            mybutton1.label ="X";
            mybutton1.addEventListener(MouseEvent.CLICK, remover);
            g.addElement(mybutton1);
    //      setting1(mybutton1);
            n++;
        }

        public function addGroup(event:MouseEvent): void
        {
            var s:String;
            n = n+1;
            s = "NewGroup"+ "_"+ n.toString;
            var myGroup:Group = new Group();
            myGroup.id = s;
            main.addElement(myGroup);
        //  setElementIndex(myGroup, n);
            settings(myGroup); 
        }

    ]]>
</fx:Script>

<s:Button x="422" id="wow"   y="139" label="Add Group"  click="addGroup(event)"/>

<s:HGroup id="main" x="6" y=开发者_开发知识库"168" width="750" height="490">
</s:HGroup>


This should work:

protected function remover(event:MouseEvent):void
{
  main.removeElement(Group(Button(event.currentTarget).parent));
}


You need to look into using DataGroup to create ItemRenderers (your groups) which has a button within it. Everything is based on a data collection (like ArrayCollection) that you manage. It makes everything easier because if you bind the ArrayCollection to the dataProvider property of the DataGroup and remove an item from the collection, your DataGroup will automatically update and remove the display item for you.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜