gpt4 book ai didi

apache-flex - 柔性 : Accessing functions/components accross mxml pages

转载 作者:行者123 更新时间:2023-12-01 13:09:37 27 4
gpt4 key购买 nike

为简单起见,假设我有两个 flex mxml 页面。

表单.mxml
按钮.mxml

如果 form.mxml 页面有以下代码,它应该可以正常工作:

<custom:SelectView dSource="{_thedata}" id="form" visible="false">
</custom:SelectView>

<mx:LinkButton label="Show" id="lbShow" click="form.visible=true;>
<mx:LinkButton label="Show" id="lbHide" click="form.visible=false;>

但是如果代码是这样的:

表单.mxml

 <custom:SelectView dSource="{_thedata}" id="form" visible="false">
</custom:SelectView>

按钮.mxml

<mx:LinkButton label="Show" id="lbShow" click="form.visible=true;>
<mx:LinkButton label="Show" id="lbHide" click="form.visible=false;>

如何从 button.mxml 调用来更改 form.mxml

---- 更多细节 ---

我的页面实际上是这样的:其中 query:AdvancedSearchFields 基本上是在页面中包含一个 flex 表单,我希望它在搜索完成后显示/隐藏下面的自定义 View 。

<query:AdvancedSearchFields searchType="projects" searchCategory="advanced" visible="true" id="AdvancedSearch" />

<custom:SelectView dSource="{_searchResults}" id="sv" visible="false">

最佳答案

您可以编写自定义方法来处理按钮单击事件并引发自定义事件。然后在 form.mxml 中你可以处理那个事件。

像这样拆分它更简洁一些,因为它使 button.mxml 文件独立工作。让 Button.mxml 直接引用您的表单会导致两者之间的紧耦合,通常您应该避免紧耦合。

编辑:我只是有另一个想法,它也避免了紧耦合并且更简单一些:

form.mxml

<custom:SelectView dSource="{_thedata}" id="form" visible="{buttons.showForm}">
</custom:SelectView>

<!-- include your buttons.mxml component using an ID of "buttons" -->

按钮.mxml

<mx:Script>
<![CDATA[
[Bindable] public var showForm:Boolean = true;
]]>
</mx:Script>

<mx:LinkButton label="Show" id="lbShow" click="this.showForm=true;">
<mx:LinkButton label="Hide" id="lbHide" click="this.showForm=false;">

这实质上是通过使用变量绑定(bind)来模拟使用自定义事件。每当按钮中的 showForm 变量发生变化时,SelectView 的可见属性将通过绑定(bind)进行更新。这比创建自定义事件更轻量(尽管我认为自定义事件的设计更适合它)。

关于apache-flex - 柔性 : Accessing functions/components accross mxml pages,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/187795/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com