0

我得到了一些代码:

...
<fx:Declarations>
<s:Animate id="toRight"   target="{cp.layout}">
<s:SimpleMotionPath property="horizontalScrollPosition"                                     valueFrom="{cp.layout.horizontalScrollPosition}" valueTo="{cp.layout.horizontalScrollPosition+42}"/>
            </s:Animate>
</fx:Declarations>
....
....
<s:List id="cp" horizontalScrollPolicy="off"  itemRenderer="com.mRenderer" horizontalCenter="1" verticalCenter="1" change="changeEvt(event)" borderAlpha="0"  width="458" height="65"   initialize="initList();"  >

......

我使用该动画来平滑列表中的箭头移动。

但我收到了一些警告:

数据绑定将无法检测到“布局”的分配。

我知道布局在列表中不可绑定。但它不是自定义类。我怎样才能防止这种情况?

4

1 回答 1

1

所以你正在使用效果来为布局对象Animate设置动画?horizontalScrollPosition我认为它工作正常。

您收到的警告是由这个花括号绑定表达式触发的:target="{cp.layout}". 警告告诉您,如果控件的属性更改,List控件不会调度任何绑定事件。layout因此,如果您的应用程序中的某些内容更改了列表的布局,您的动画效果将停止工作。

这只是一个警告,只要您不希望更改布局,您的代码应该可以正常工作。

如果您想让警告消失,您有以下三种选择:

  • 更新您的编译器设置,以免生成此警告(坏主意)
  • 不要在花括号表达式中使用不可绑定的属性,而是使用返回不可绑定属性的函数调用。
  • 使用“creationComplete”事件处理程序来分配target动画的属性

在绑定表达式中使用函数的示例:

<s:Animate target="{getAnimationTarget()}" />

private function getAnimationTarget():Object
{
    return cp.layout;
}

虽然可能会发生同样的问题(如果列表的布局发生更改,则列表不会调度任何事件来更新绑定),上述语法应该可以防止生成警告。当花括号表达式包含函数调用时,Flex 编译器不会根据设计生成此警告。

使用“creationComplete”事件的示例List

<s: List creationComplete="myFunction() />

private myFunction()
{
    toRight.target = cp.layout;
}
于 2013-05-15T00:16:06.943 回答