0

我们正在尝试这样做:

<rollOverEffect>
    <AnimateProperty property="scaleX" toValue="{originalWidth + scaleFactor}" />
</rollOverEffect>

然而,似乎 toValue 的效果总是 NaN。如果我将值设置为常数,效果会起作用。难道不能使用数据绑定来实现这样的效果吗?


附录: originalWidth 和 scaleFactor 都是可绑定的。我设法通过将效果移出rollOverEffect-tag,给它和id,然后像这样绑定到它来实现这个工作:

<AnimateProperty id="scaleEffect" property="scaleX" toValue="{originalWidth + scaleFactor}" />
<MyComponent rollOverEffect="{scaleEffect}" />

知道为什么这有效而以前的代码无效吗?后一个片段创建了第二个不必要的绑定并且不那么可读,但至少它可以工作。


附录: 以下代码突出显示了该问题。无论滑块设置为什么,效果的 angleTo 属性的值将始终设置为滑块初始值设置的值。

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:VBox horizontalCenter="0" verticalCenter="0">
    <mx:Label text="Rotation (mouse over on canvas triggers effect):" />
    <mx:HSlider id="slider" width="200" minimum="0" maximum="360" value="90" />

    <mx:Spacer height="50" />

    <mx:Canvas borderStyle="solid" borderThickness="1" borderColor="#ff0000" backgroundColor="#0000ff" width="200" height="200">
        <mx:rollOverEffect>
            <mx:Rotate angleTo="{slider.value}" duration="500" />
        </mx:rollOverEffect>

        <mx:rollOutEffect>
            <mx:Rotate angleTo="{-slider.value}" duration="500" />
        </mx:rollOutEffect>
    </mx:Canvas>
</mx:VBox>
</mx:Application>

与以下实际产生预期结果的代码进行比较:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Rotate id="rollOver" angleTo="{slider.value}" duration="500" />
<mx:Rotate id="rollOut" angleTo="{-slider.value}" duration="500" />

<mx:VBox horizontalCenter="0" verticalCenter="0">
    <mx:Label text="Rotation (mouse over on canvas triggers effect):" />
    <mx:HSlider id="slider" width="200" minimum="0" maximum="360" value="90" />

    <mx:Spacer height="50" />

    <mx:Canvas rollOverEffect="{rollOver}" rollOutEffect="{rollOut}" borderStyle="solid" borderThickness="1" borderColor="#ff0000" backgroundColor="#0000ff" width="200" height="200" />
</mx:VBox>
</mx:Application>

所以本质上问题是什么,为什么绑定在第一个示例中不起作用?没有错误或警告可以告诉您这一点,我也无法在文档中找到任何关于此的内容,这可能是一个错误吗?

4

1 回答 1

0

您需要向我们展示更多代码。你可以试一下下面的代码吗?这行得通吗?

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
    <!-- Simple exemplo to demonstrate the AnimateProperty effect. -->

    <mx:Sequence id="animateScaleXUpDown" >
        <mx:AnimateProperty property="scaleX" fromValue="{ns.value}" toValue="{ns.minimum}" duration="1000" />
        <mx:AnimateProperty property="scaleX" fromValue="1.5" toValue="1" duration="1000" />    
    </mx:Sequence>

    <mx:Panel title="AnimateProperty Effect Example" width="75%" height="75%" 
        paddingTop="10" paddingLeft="10" paddingRight="10" paddingBottom="10">

        <mx:Text width="100%" color="blue" 
            text="Click on the image to use the AnimateProperty effect with the scaleX property."/>

        <mx:Image id="flex" source="http://stackoverflow.com/content/img/stackoverflow-logo.png"
            mouseDownEffect="{animateScaleXUpDown}"/>
        <mx:NumericStepper id="ns" width="62" value=".5" minimum="1" maximum="3" stepSize="0.5" enabled="true"/>

    </mx:Panel>

</mx:Application>
于 2009-04-28T17:09:35.780 回答