Flex 4 - 当容器的子级依赖于状态时如何循环它们

发布于 2024-11-30 06:24:01 字数 812 浏览 1 评论 0原文

Flex 的新状态重新设置了标有 includeIn/excludeFrom 的视觉项目的父级。如果我有一个包含 5 个受状态控制的子元素/元素的组 (MainGroup),是否还有办法获取对 MainGroup 子元素的引用? mainGroup.numChildren 和 mainGroup.numElements 不起作用,因为子级被重新设置了父级。最好的情况下,它们显示 1。

<s:states>
   <s:State name="view1State" />
   <s:State name="view2State" />
   <s:State name="view3State" />
   <s:State name="view4State" />
</s:states>

<s:Group id="mainGroup">
    <shipping:OrderShipping id="view1"
            includeIn="view1State" />
    <payment:OrderPayment id="view2"
            includeIn="view2State" />
    <verification:OrderVerification id="view3"
            includeIn="view3State" />
    <confirmation:OrderConfirmation id="view4"
            includeIn="view4State" />
</s:Group>

Flex's new States re-parents visual items that are marked with includeIn/excludeFrom. If I have a Group (MainGroup) with 5 children/elements that are state controlled, is there still a way to get a reference to MainGroup's children? mainGroup.numChildren and mainGroup.numElements don't work since the children are re-parented. At best, they show 1.

<s:states>
   <s:State name="view1State" />
   <s:State name="view2State" />
   <s:State name="view3State" />
   <s:State name="view4State" />
</s:states>

<s:Group id="mainGroup">
    <shipping:OrderShipping id="view1"
            includeIn="view1State" />
    <payment:OrderPayment id="view2"
            includeIn="view2State" />
    <verification:OrderVerification id="view3"
            includeIn="view3State" />
    <confirmation:OrderConfirmation id="view4"
            includeIn="view4State" />
</s:Group>

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

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

发布评论

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

评论(4

恬淡成诗 2024-12-07 06:24:02

如果你想让状态控制visible/includeinlayout而不是parenthood,就这样做

<s:states>
    <s:State name="view1State" />
    <s:State name="view2State" />
    <s:State name="view3State" />
    <s:State name="view4State" />
</s:states>
<s:Group id="mainGroup">
    <shipping:OrderShipping id="view1" 
        visible="false" 
        includeInLayout="false" 
        visible.view1State="true" 
        includeInLayout.view1State="true"/>
    <payment:OrderPayment id="view2" 
        visible="false" 
        includeInLayout="false" 
        visible.view2State="true" 
        includeInLayout.view2State="true"/>
    <verification:OrderVerification id="view3" 
        visible="false" 
        includeInLayout="false" 
        visible.view3State="true" 
        includeInLayout.view3State="true" />
    <confirmation:OrderConfirmation id="view4" 
        visible="false" 
        includeInLayout="false"
        visible.view4State="true" 
        includeInLayout.view4State="true"/>
</s:Group>

If you want states to control visible/includeinlayout rather than parenthood, just do it like this

<s:states>
    <s:State name="view1State" />
    <s:State name="view2State" />
    <s:State name="view3State" />
    <s:State name="view4State" />
</s:states>
<s:Group id="mainGroup">
    <shipping:OrderShipping id="view1" 
        visible="false" 
        includeInLayout="false" 
        visible.view1State="true" 
        includeInLayout.view1State="true"/>
    <payment:OrderPayment id="view2" 
        visible="false" 
        includeInLayout="false" 
        visible.view2State="true" 
        includeInLayout.view2State="true"/>
    <verification:OrderVerification id="view3" 
        visible="false" 
        includeInLayout="false" 
        visible.view3State="true" 
        includeInLayout.view3State="true" />
    <confirmation:OrderConfirmation id="view4" 
        visible="false" 
        includeInLayout="false"
        visible.view4State="true" 
        includeInLayout.view4State="true"/>
</s:Group>
‖放下 2024-12-07 06:24:02

我在我的一个应用程序中遇到了类似的情况,这就是我完成任务的方式。我觉得有必要这么说,虽然这很有效,但我觉得它有点老套。考虑到这一点:

  1. 创建另一个状态,我们将其称为作弊。将此状态设置为默认状态(将其放在 states 数组中的第一个位置。
  2. 更新所有视图以包含在此状态中。
    例如,
  3. 创建一个名为 views< 的 Array 类型的新类成员/代码>。
  4. 添加 creationComplete 事件处理程序。在处理程序中填充 views 并引用每个视图。例如,views = [view1, view2, view3, view4];
  5. 将状态更改为您的“第一个”(非作弊)状态:setCurrentState("view1State ");

毕竟,无论您的应用程序当前处于哪种状态,您的 views 数组都将引用每个视图。

I have a similar situation in one of my applications and this is how I accomplished things. I feel obliged to say that, though this works I feel it is a bit hacky. With that in mind:

  1. Create another state, we'll call it cheating. Make this state the default one (put it first in your states array.
  2. Update all your views to be included in this state.
    E.g., <shipping:OrderShipping id="view1" includeIn="cheating,view1State" />
  3. Create a new class member of type Array called views.
  4. Add a creationComplete event handler. In the handler populdate views with references to each of the views. E.g., views = [view1, view2, view3, view4];
  5. Change the state to your "first" (non-cheating) state: setCurrentState("view1State");

After all this your views array will have references to each of the views regardless of which state your application is currently in.

走走停停 2024-12-07 06:24:02

我不确定底层状态实现是否会删除/添加子组件或更改其可见性。

如果是前者,我会尝试这样的方法:

for (var x : int = 0; x<mainGroup.numChildren ; x++){
 var child : UIComponent = mainGroup.getChildAt(x);
 if(child.parent){
   // The child has a parent, so it must be displayed; do your processing 
 } else {
   // really this should never occur 
 }
}

如果是可见性问题,则执行以下操作:

for (var x : int = 0; x<mainGroup.numChildren ; x++){
 var child : UIComponent = mainGroup.getChildAt(x);
 if(child.visible){
   // The child is displayed; do your processing 
 } else {
   // child isn't displayed
 }
}

我猜第一种方法是正确的方法。

[注意我在浏览器中编写了这段代码]

I'm not sure if the underlying state implementation removes / adds children to the component or changes their visibility.

If the former, I'd try something like this:

for (var x : int = 0; x<mainGroup.numChildren ; x++){
 var child : UIComponent = mainGroup.getChildAt(x);
 if(child.parent){
   // The child has a parent, so it must be displayed; do your processing 
 } else {
   // really this should never occur 
 }
}

If it is a visibility issue, then do this:

for (var x : int = 0; x<mainGroup.numChildren ; x++){
 var child : UIComponent = mainGroup.getChildAt(x);
 if(child.visible){
   // The child is displayed; do your processing 
 } else {
   // child isn't displayed
 }
}

I'd guess the first approach is the correct one.

[Note I wrote this code in the browser]

橘虞初梦 2024-12-07 06:24:02

我得到了最佳答案!好吧,我会让你决定。只需对 states 数组进行操作...

 for each (var viewState:State in mainDocument.states)
{
    var overrides:Array = viewState.overrides;

    for (var i:int = 0; i < overrides.length; i++)
    {
        var addItems:AddItems = overrides[i];
        if (addItems.destination === mainDocument.mainGroup)
            trace((addItems.items as UIComponent).name);
    }

}

I got the best answer! Well, I will let you decide. Just operate on the states array...

 for each (var viewState:State in mainDocument.states)
{
    var overrides:Array = viewState.overrides;

    for (var i:int = 0; i < overrides.length; i++)
    {
        var addItems:AddItems = overrides[i];
        if (addItems.destination === mainDocument.mainGroup)
            trace((addItems.items as UIComponent).name);
    }

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