开发者

Adding buttons to a dynamically created panel

开发者 https://www.devze.com 2023-03-26 04:11 出处:网络
I am dynamically creating panels based on information i get from an XML file but i\'m having a problem with adding buttons to these 开发者_运维技巧panels. These buttoms are also created based on infor

I am dynamically creating panels based on information i get from an XML file but i'm having a problem with adding buttons to these 开发者_运维技巧panels. These buttoms are also created based on information taken from the XML file. The problem seems to be in the way i give the panels an Id name. Any help you can give would be great.

private function sidebar():void{
            for each (value in xmlObj.SPORT.@Event)
            {
                var myInstance4:spark.components.Panel = new spark.components.Panel();
                myInstance4.title = value;
                myInstance4.id = value;
                sidebarbox.addChild(myInstance4);
                Alert.show(myInstance4.id)
                for each (value2 in xmlObj.SPORT.MatchResult.COMPETITION.@Comp)
                {
                    var myInstance3:spark.components.Button = new spark.components.Button();
                    myInstance3.label = value2;
                    myInstance3.addEventListener("click",changeIt);
                    myInstance3.id=value2;      
            //      value.addChild(myInstance3);
                //  value.addElement(myInstance3);
                }

            }
        }


Use myInstance4.addElement to add the children.

You are already creating an instance by calling

var myInstance4:spark.components.Panel = new spark.components.Panel();

If you created these elements in MXML, yes, you would be using the id property to uniquely identify each object when you are using it in ActionScript. For example

<s:Button id="myButton" label="My Button" />

protected function creationCompleteEvent(event:FlexEvent):void
{
     myButton.doSomething();
}

BUT,

if you created it using ActionScript, you do not need to set the id property to access it as long as you have a reference to that object.

protected function creationCompleteEvent(event:FlexEvent):void
{
   var myNewButton:Button = new Button();
   //You do not need to set the id here
   myNewButton.doWhatEver();
}
0

精彩评论

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

关注公众号