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

标签 apache-flex mxml

为简单起见,假设我有两个 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/

相关文章:

c - 如何在alchemy中给出相关头文件的路径?

apache-flex - 如何仅在标签中的特定单词上显示工具提示?

apache-flex - Asdoc 为包含单独的 .as 文件的 MXML 组件抛出错误

apache-flex - 修补 flex 框架以立即显示预加载器?

apache-flex - Flex 4 如何以 html 表格类型的方式布局 Spark 控件

apache-flex - 为 flex 中的所有表单项自动显示屏幕键盘

apache-flex - fla文件,代码(AS)在哪里

apache-flex - Flex 弹出窗口管理器,在弹出窗口外按下鼠标可删除弹出窗口

flash - 通过 mxml 中的函数传递值?

apache-flex - 如何阻止数据网格的第一行 itemRenderer 实例化/添加/初始化/等两次?