Animating child elements in Flex 4

怎甘沉沦 提交于 2019-12-11 12:50:00

问题


Anyone know how to animate the size/position of child elements of a layout in Flex 4 ?

Example:

I have a list component with a custom layout. I want when I change the positions of the child elements I want them to animate their move to the new positions.


回答1:


There is currently no built in way, nor plans, to make animated layouts in Flex 4 :/.

What I've done to make this happen is to animate the setting of "setLayoutBoundsPosition" and "setLayoutBoundsSize" in the layout. So instead of creating a "Move" and "Resize" effect for each item in the layout, which would actually set the width and height explicitly, set the matrix. Then make sure the layout isn't invalidated again (which will happen if you set the width/height directly), or you might start getting an infinite loop. You might have to do some tricks to get this to work right (I haven't got it to work quite right with the Spark Effects, but it's really easy to do with Tweener/Tweenmax, since they have plugins and such to use "setActualSize" or "setLayoutBoundsSize", etc.).

I use TweenMax to animate layouts, and they have a few plugins to make this easy. TweenMax visibly looks like 3x faster (20 fps vs 7fps) than Spark Effects, too, so I'd go with that. It looks something like this, in the updateDisplayList method of your layout.

TweenMax.to(child, duration, {setLayoutBoundsPosition:{x:childX * i, y:childY * i}});




回答2:


Just like you would normally...

public override function updateDisplayList(width:Number, height:Number) : void {
    for (var i:uint = 0; i < target.numElements; i++)
    { 
       var resizeElement:Resize = new Resize(target.getElementAt(i) as IVisualElement);
       resizeElement.widthTo = 500;
       resizeElement.play();
    }
}


来源:https://stackoverflow.com/questions/1582863/animating-child-elements-in-flex-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!