Flex AS3:组合框设置可见为 false 不隐藏

发布于 2024-08-27 08:44:42 字数 1704 浏览 8 评论 0原文

我在视图中有一个组合框,它接收有关应用程序状态更改的信息,然后应该根据整个应用程序状态显示或隐藏它的子项。

它接收状态更改消息,跟踪正确的值,它执行它应该执行的操作,但是,它似乎不起作用。本质上,它所需要做的就是在一种状态下隐藏组合框,并在另一种状态下再次显示它。

这是代码:

public function updateState(event:* = null):void {
        trace("Project Panel Updating State");
        switch(ApplicationData.getSelf().currentState) {
            case 'login':
                this.visible = false;
                break;
            case 'grid':
                this.visible = true;
                listProjects.includeInLayout = false;
                listProjects.visible = false;
                trace("ListProjects: " + listProjects.visible);
                listLang.visible = true;
                break;
            default:
                break;


        }
    }

这是 MXML:

    <mx:HBox>
    <mx:Button id="btnLoad" x="422" y="84" label="Load" enabled="true" click="loadProject();"/>
    <mx:ComboBox id="listProjects" 
                x="652" 
                y="85" 
                editable="true" 
                change="listChange()" 
                color="#050CA8" 
                fontFamily="Arial" />   
    <mx:Label x="480" y="86" text="Language:" id="label3" fontFamily="Arial" />
    <mx:ComboBox id="listLang" 
                x="537" 
                y="84" 
                editable="true" 
                dataProvider="{langList}" 
                color="#050CA8" 
                fontFamily="Arial" 
                width="107" 
                change="listLangChange(event)"/>
    <mx:CheckBox x="830" y="84" label="Languages in English" id="langCheckbox" click='toggleLang()'/>
</mx:HBox>

I have a combobox in a view that receives information about application state changes, and then is supposed to show or hide it's children based on the whole application state.

It receives state change messages, it traces the correct values, it does what it's supposed to do, however, it just doesn't seem to work. Essentially, all it needs to do is hide a combobox during one state, and show it again during another state.

Here is the code:

public function updateState(event:* = null):void {
        trace("Project Panel Updating State");
        switch(ApplicationData.getSelf().currentState) {
            case 'login':
                this.visible = false;
                break;
            case 'grid':
                this.visible = true;
                listProjects.includeInLayout = false;
                listProjects.visible = false;
                trace("ListProjects: " + listProjects.visible);
                listLang.visible = true;
                break;
            default:
                break;


        }
    }

Here is the MXML:

    <mx:HBox>
    <mx:Button id="btnLoad" x="422" y="84" label="Load" enabled="true" click="loadProject();"/>
    <mx:ComboBox id="listProjects" 
                x="652" 
                y="85" 
                editable="true" 
                change="listChange()" 
                color="#050CA8" 
                fontFamily="Arial" />   
    <mx:Label x="480" y="86" text="Language:" id="label3" fontFamily="Arial" />
    <mx:ComboBox id="listLang" 
                x="537" 
                y="84" 
                editable="true" 
                dataProvider="{langList}" 
                color="#050CA8" 
                fontFamily="Arial" 
                width="107" 
                change="listLangChange(event)"/>
    <mx:CheckBox x="830" y="84" label="Languages in English" id="langCheckbox" click='toggleLang()'/>
</mx:HBox>

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

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

发布评论

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

评论(2

网白 2024-09-03 08:44:43

您的代码中并不清楚 updateState 函数在何处以及如何被调用,并且为了进一步了解解决方案,我认为我需要看到这一点。但是,我认为您可能会考虑采用不同的方法。

您是否尝试过使用视图而不是手动显示和隐藏事物以及设置属性?我认为,如果您的开关中的每种情况都有不同的视图状态(例如“登录”等),那么您的代码会更简单。然后所有显示隐藏的内容都将成为设计时活动而不是运行时活动,您所拥有的一切要做的就是设置当前状态。

如果您将状态名称与 ApplicationData currentState 值相匹配,您甚至可以完全取消 updateState 函数。

It's not that clear form your code where and how the updateState function gets called, and to get any further into a solution I think I would need to see that. However, I think you may like to consider a different approach.

Have you tried using views instead of manually showing and hiding things and setting properties? I think you would have simpler code if you had a different view state for each of the cases in your switch, e.g. 'login' etc. Then all the showing hiding stuff becomes a design-time activity rather than run-time and all you have to do is set the current state.

If you matched your state names with your ApplicationData currentState values you may even be able to do away with the updateState function completely.

悲凉≈ 2024-09-03 08:44:43

你有没有尝试过改变

updateState(事件:* = null):void

对此

updateState(事件:Event = null):void

我仍在研究 event:* ,到目前为止我发现的所有内容都有 Event 而不是 *。会重新发帖还在看

Have you tried changing

updateState(event:* = null):void

to this

updateState(event:Event = null):void

Im still looking into the event:* and everything I have found so far has Event instead of *. Will repost still looking

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