I've been playing around with animation and layout recently, and I wondered how I could combine the two. That is, when a container changes state and wants to re-layout its children, wouldn't it be nice if it could animate that change instead of simply blinking them all into place?
Suppose you have a picture-viewing application, where you're looking at thumbnails of the photos. Sometimes you want them to be quite small so that you can see more pictures in the view. But sometimes you want them to be larger instead so that you can see more details in any particular picture. So there's a slider that allows you to dynamically control the thumbnail sizes.
By default, in this application as well as other real applications that it's modeled on, changing the thumbnail sizes causes the application to re-display itself with all of the changed thumbnails in their new location. But what I want is for the change in size to animate, where all of the thumbnails will move and resize to their new location and dimension.
It turns out that this is not that hard to achieve, using the built-in effects of Flex.
11 comments:
View Source doesn't work :))
ARGH!
Another casualty of my sub-optimal blogging setup (can't host the SWF and source files locally on blogspot, so I serve them from elsewhere and it all gets confused...)
I updated the SWF and uploaded a .zip file; now just click on the link to download the zipped source directly.
Thanks,
Chet.
Nice work! I have been developing a slide application recently. One problem I have run into is using bindable variables in an mx:Move. For example: (I am using # instead of "<" and ">")
#mx:Move target="{from_grid}" duration="500" xFrom="{slide_from_grid_from}" xTo="{slide_from_grid_to}"/#
#mx:Move target="{to_grid}" duration="500" xFrom="{slide_to_grid_from}" xTo="{slide_to_grid_to}"/#
If I replace the xTo's with the actual numbers, the slide occurs smoothly. Using bindables, the slide does not really even occur. It's more of a sudden move. Do you think this is a bug or is there a better solution?
(I have verified that the bindables have the correct values)
Thanks!
Hey Chet,
Here is a challenge for you ;-)
When I saw your app i immediately thought it would be cool if the change already happends while dragging and not only when you release it. This way the user gets immediate feedback of what`s happening and I think that`s the motivation for animations in UIs.
I think this is where the build in effects fall short. They don`t really work if the animation target change often and abrupt. I made a AIR version http://www.richapps.de/?p=150 that uses some old school flash animation techniques but lacks the beauty of your code. So how would you do this in a good way?
Have a great day
Benz
Tony: Sorry, I didn't see this comment until today (normally get notified when there's a comment, but somehow didn't on this one).
I think the problem might come from how effects are instantiated: the variables xFrom/xTo/etc. are provided to a factory class (Move). When the effect is played, the factory creates instances on the targets with the current values. If you bind the attributes, they should have valid values at the time the effect is play()'d, but changing those values will not cause the effect to re-play (or to re-create more instances with the new values).
Does that help make sense of this?
Benz: Thanks for the idea; I'll chew on this (about time for another demo app anyway...). The trick, I think, in this kind of realtime interaction between the slider value (dragged in realtime) and animations to the current value (delayed because, well, animations happen over time). Getting it to feel natural and not laggy (animations completing before running the next one) or choppy (animatings getting cut off to react to the new value) maybe require some tweaking.
By the way, I'm curious about the problems you have with the Flex effects (as you said in your blog). I'm currently working on some new effects infrastructure and classes for Flex4, including reworking some of the Tween functionality. It would be great to know more about issues that you have with the current stuff. (I keep meaning to write a post on this to gather feedback generally, but in the meantime...)
Thank you for getting back to me Chet. I actually solved the problem a while ago. I am however running into a much more interesting problem now with one of my apps.
I need to dynamically change the background color of a widget I created. But when I change the color, it messes up the layout.
I used validateNow() to try to fix this issue, but for some reason that only works for the first time I change the color. If I change it twice, the layout remains messed up.
Do you have any ideas for this? I have probably spent 6-8 hours investigating this issue already.
Thank you!
Hi Chet,
First thing I wanna say is Great Video, Props to you!!! I'm new to flex, I've been peeking it a little bit now and just started doing my first couple of apps.
Excuse my ignorance but I just downloaded the solution, tried running and I got the following error:
unable to resolve 'assets/a.jpg' for transcoding
I did create the folder and a "a.jpg" file. But I still get the same error, I tried to change the direction of the slash and still got the error. Any Pointers??
By the way, I'm from Argentina, I'm waiving the Flex flag here, if u wanna join my LinkedIn group http://www.linkedin.com/e/gis/976927
try to right click on the folder and hit refresh...flex can be weird
hi chet,
I am learning Flex seince 3 month, but your video has help me to learn flex at an level at which i was looking...
Thanks Chet...
hi chet,
I am learning Flex seince 3 month, but your video has help me to learn flex at an level at which i was looking...
Thanks Chet...
Hi Chet,
I was trying the example and i noticed that smoothing wasn't working. I though you weren't writting it explicitly but i saw your loadComplete event. I don't know why this event is not being called. I added another eventListener (Mouse Click) and it worked. It's not really cool clicking on every image you load in the Slide, so i do the smoothing when the image is being loaded to the slide, at Slide's addChild.
here's the code.
//Slide.as
override public function addChild(child:DisplayObject):DisplayObject
{
var retValue:DisplayObject = super.addChild(child);
image = Image(child);
Bitmap(image.content).smoothing = true;
return retValue;
}
With this, the smoothing occurs after image is loaded in the slide.
I hope you update the code.
It's just to delete image.addEventListener(Event.COMPLETE, loadComplete); at addImages in SlideContainer and to add Bitmap(image.content).smoothing = true; at Slide's addChild after image is setted.
Grettings from Cali, Colombia.
Jonathan Morales Vélez
Post a Comment