【问题标题】:Calling a state view from the main class in an MXML component in FLEX 4在 FLEX 4 的 MXML 组件中从主类调用状态视图
【发布时间】:2013-07-14 22:58:14
【问题描述】:

我创建了一个主类,它有 5 个状态:

    <s:State name="loginState" />

    <s:State name="librariesState"/>

    <s:State name="createState"/>

    <s:State name="profilesState"/>


</s:states>

每个状态都在一个新的 MXML 组件文件中创建,并在主类中调用如下:

    <components:Homepage includeIn="homeState"/>

    <components:LibrariesPage includeIn="librariesState"/>

<components:CreatePage includeIn="createState"/>

<components:ProfilesPage includeIn="profilesState"/>

在 homeState 中,我有三个按钮,通过单击将我带入 libraryState、createState 和 profilesState。我的问题是如何在 Homepage MXML 组件中调用状态视图(在主类中定义)。我试着写了click="currentState='librariesState',但是在Homepage中没有看到状态LibrariesState。如何从MXML组件中的主类中调用状态?

【问题讨论】:

    标签: flex4 flash-builder


    【解决方案1】:

    您确定需要某种类型的 ViewStack 吗?通常,当您使用 State 时,是因为您希望对同一视图进行相对较小的更改。诸如“adminState”之类的东西与“userState”形成对比;从而某些按钮在 userState 中被禁用或处于非活动状态,在 adminState 中启用。

    【讨论】:

    • 这是我构建项目的方式,但现在当我在 MXML 组件中时无法进入主页。你知道怎么可能吗?
    【解决方案2】:

    我发现:很简单!在组件类中可以使用 this.parentApplication.currentState="createState";

    这是可以从组件访问 main 中的每个方法的方式: 这个 parentApplication.method()

    我希望它可以为像我这样的初学者节省时间。

    【讨论】:

      猜你喜欢
      • 2011-05-28
      • 2010-12-08
      • 2011-02-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多