开发者

Panels creation at runtime can't see them

开发者 https://www.devze.com 2023-04-08 09:57 出处:网络
My problem is i am trying to make a panel. My button in in Main.mxml whereas the panel functions are defined in panel_Create.mxml. the code works fine. In panel_Create their are functions to create pa

My problem is i am trying to make a panel. My button in in Main.mxml whereas the panel functions are defined in panel_Create.mxml. the code works fine. In panel_Create their are functions to create panels at runtime. The problem i am facing is when i run the program it wont show the panels but it does increase the value of n and after 8 clicks it gives alert message. Please tell me why cant i see panels. The code works fine when i put all the code in Main.mxml

<fx:Script>
            <![CDATA[

                import Components.panel_Create;
                import mx.controls.Alert;
                import spark.components.Button
                public var adminPanel:panel_Create = new panel_Create();

                public var n:Number = 0;
                public function panel(event:MouseEvent): void
                {
                    if ( n < 8)
                    {
                        adminPanel.panel_Create(n);
                        n++;
                    }
                    else
                    Alert开发者_Python百科.show('More Panels Not Allowed', 'Alert Box', mx.controls.Alert.OK);          
                }
            ]]>
        </fx:Script>

        <s:Button id="add" includeIn="State1" x="398" y="10" label="Add Panel" click="panel(event)"/>
        <Components2:panel_Create includeIn="State1" x="10" y="66" width="737" height="599">
        </Components2:panel_Create>

    </s:Application>


I believe that the 8 panels are created and based on the code in one of your comments they are added as child elements to the adminPanel.

The problem is that your adminPanel is never added to the stage so is not visible.


Try this instead:

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx">
    <fx:Script>
        <![CDATA[
            private var panels:Array = [];

            private function addPanel():void
            {
                if (panels.length < 8)
                {
                    var panel:Panel = new Panel();
                    panel.title = "Panel "+(panels.length + 1);
                    panels.push(panel);
                    addElement(panel);
                }else{
                    trace('More Panels Not Allowed');
                }                   
            }
        ]]>
    </fx:Script>
    <s:Button label="Add Panel" click="addPanel()"/>
</s:Application>


adminPanel is not being created. you have to do addElement(adminPanel) itself

if ( n < 8)
                    {
                        adminPanel.panel_Create(n);
                        addElement(adminPanel)
                        n++;
                    }
0

精彩评论

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

关注公众号