如何创建mxml实例并传递参数?

发布于 2024-10-11 16:55:35 字数 196 浏览 0 评论 0原文

我想创建 mxml 实例(在我的例子中为 EventList)并传递参数。我的事件列表是面板列表,因此我想传递参数并动态生成 n 个面板(要传递的 n 个参数)。我有一个主应用程序,当我单击第一个按钮时,我想要在第二个按钮上生成 3 个面板(n = 3),20 个面板(n = 20)等。 我该怎么做?我如何传递 n 以及显示列表的最佳方式是什么?我想在单击切换按钮时生成列表!

i want to create instance of mxml (in my case EventList) and pass parameters. My Event List is a list of panels so I want to pass parameters and generate dynamically n number of panels (n-parameter to pass). I have the main app where I have toggle button bar when I click on the first I want for example to generate 3 panels (n=3) on the second button 20 panels (n=20) etc.
How can I do this? How can I pass n and what is the best way to show the list? I whant to generate the list when I click on the toggle button!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

土豪 2024-10-18 16:55:35

使用 xmlnamespace(xmlns) 访问源文件夹中的 mxml 文件。我创建了一个应用程序,其中包含 xmlns="*"(* 表示您可以访问源文件夹中的任何组件)来访问 myEvenList 组件。我在这里传递了 n 值本身。查看示例。HTH。

togglePanelCount.mxml

   <?xml version="1.0" encoding="utf-8"?>
    <mx:Application name="ToggleButtonBar_toggleOnClick_test"
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical"
    verticalAlign="top"
    backgroundColor="white" xmlns:eventList="*">                                 <mx:ToggleButtonBar id="toggleButtonBar"
                    dataProvider="{viewStack}" /><mx:ViewStack id="viewStack"
        width="100%"
        height="100%">
    <eventList:myEventList n="5" id="List1"/>
    <eventList:myEventList n="20" id="List2"/>
 </mx:ViewStack></mx:Application>

myEvenList.mxml

 
    

PS:将 n 作为公共属性本身为您提供了一种传递面板计数的方法。即使在应用程序中的 mx:Script 标记中,您也可以实例化 myEventList 对象并设置 n 的值,而不是使用 mxml 标记。

Use xmlnamespace(xmlns) to access the mxml file in your source folder.I created an application which includes xmlns="*" (* means you can access any component in the source folder)to access the myEvenList component. i pass the n value here itself.Check out the example.HTH.

togglePanelCount.mxml

   <?xml version="1.0" encoding="utf-8"?>
    <mx:Application name="ToggleButtonBar_toggleOnClick_test"
    xmlns:mx="http://www.adobe.com/2006/mxml"
    layout="vertical"
    verticalAlign="top"
    backgroundColor="white" xmlns:eventList="*">                                 <mx:ToggleButtonBar id="toggleButtonBar"
                    dataProvider="{viewStack}" /><mx:ViewStack id="viewStack"
        width="100%"
        height="100%">
    <eventList:myEventList n="5" id="List1"/>
    <eventList:myEventList n="20" id="List2"/>
 </mx:ViewStack></mx:Application>

myEvenList.mxml

          <?xml version="1.0" encoding="utf-8"?><mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" creationComplete="createPanels()"><mx:Script>
    <![CDATA[
        import mx.controls.Alert;
        import mx.containers.Panel;
        public var n:int;
        public function createPanels():void{
         Alert.show("in create panel");
         for(var i:int =0 ;i<n;i++){
          var panel:Panel = new Panel();
          panel.title = "panel"+(i+1);
          panelList.addChild(panel);
          }
          }
    ]]>
</mx:Script><mx:VBox id="panelList" /></mx:Canvas>

PS:Having n as a public attribute itself gives you a way of passing the count of panels.Even in the mx:Script tag in the application, you can instantiate the myEventList object and set the value of n instead of using mxml tags.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文