Creating Flex Sequence Effects in ActionScript
I just started building a small administrative application and in addition to having the 24 Hour Fitness logo appear in the upper left-hand corner of the main Panel, I wanted to spice it up with a cutesy bounce effect.
At first, I created my own bounce effect by using the Sequence effect, shipped in the Flex SDK’s effects package (mx.effects.Sequence). The Sequence effect “plays multiple child effects one after the other, in the order in which they are added”. The sequence effect would combine a series of AnimateProperty effects (mx.effects.AnimateProperty) that would move the “y” value of an image from a starting y-position value to an end y-position value and then back and forth to simulate an object bouncing:
1 2 3 4 5 6 7 8 9 10 11 | <!-- Define factory sequence class --> <mx:Sequence id="bounceSeq"> <mx:AnimateProperty property="y" fromValue="-70" toValue="45" duration="500"/> <mx:AnimateProperty property="y" fromValue="45" toValue="-35" duration="450"/> <mx:AnimateProperty property="y" fromValue="-35" toValue="35" duration="350"/> <mx:AnimateProperty property="y" fromValue="35" toValue="-15" duration="250"/> <mx:AnimateProperty property="y" fromValue="-15" toValue="30" duration="150"/> <mx:AnimateProperty property="y" fromValue="30" toValue="5" duration="150"/> <mx:AnimateProperty property="y" fromValue="5" toValue="25" duration="150"/> <mx:AnimateProperty property="y" fromValue="25" toValue="23" duration="150"/> </mx:Sequence> |
I gave the first fromValue a starting position of “-70″, which for this application meant the logo would first appear off-screen. But in the end, I had trouble configuring the values to make the bounce look right. I also had trouble moving the sequence component inside it’s own mxml class definition since flex effects aren’t listed as the typical UI Components used as mxml components.
So I decided to write an ActionScript version of a Sequence effect. It was then I discovered that Flex already had incorporated several easing behaviors into the effects package. Great news!
I set off to write a sequence effect class in ActionScript that incorporated the Move easing effect. The class was incredibly easy to write since the Sequence class itself contains only one method (initInstance). By overriding that method, creating a new Move easing effect and adding that object to as a child to the sequence, the bounce effect I was looking for was easily achieved:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | package { import mx.effects.IEffectInstance; import mx.effects.Move; import mx.effects.Sequence; import mx.effects.easing.*; /** * Custom sequence to depict bounce effect */ public class Bounce extends Sequence { public function Bounce() { super(); } override protected function initInstance( instance : IEffectInstance ) : void { //create new Move effect var _move : Move = new Move(); _move.yBy = 92; //specific to this particular example _move.duration = 2000; //in milliseconds _move.easingFunction = mx.effects.easing.Bounce.easeOut; //add Move effect as a child to this sequence this.addChild( _move ); //call super to ensure parent's original logic is still executed super.initInstance( instance ); } } } |
Now as you might have noticed, this sequence contains only one effect (Move), but multiple effects could be added easily to the method above by creating a new Effect and adding it as a child to the Sequence object.
The end result looks like this (click to restart animation):
Great post! Good examples and explanation. I really like how you offered a before/after type example. The effect looks great!
Enjoyed the post. I think it is a nice, clean way to add the effects to a Flex application. Thanks!
would have saved you some effort
I quite like reading a post that can make people think.
Also, many thanks for allowing for me to comment!
Superb post however , I was wanting to know if you could write a litte more on this subject?
I’d be very thankful if you could elaborate a little bit further.
Cheers!
Say, you got a nice blog article.Really looking forward to read more. Really Cool. sex animation
Woman of Alien Great do the job you ave carried out, this website is de facto interesting with amazing information. Time is God as method of preserving everything from occurring at once.
Thanks for sharing, this is a fantastic article post.Really looking forward to read more. Awesome.
you ave gotten an awesome weblog right here! would you prefer to make some invite posts on my blog?
You are my inhalation , I own few web logs and occasionally run out from to post.
Yes. It should work. If it doesn at send us an email.
Its hard to find good help I am forever proclaiming that its hard to find good help, but here is
Really enjoyed this post.Thanks Again. Great.
This is one awesome article.Much thanks again.
This is one awesome post.Much thanks again. Great.
I truly appreciate this blog post.Much thanks again. Fantastic.
I?ve learn a few good stuff here. Definitely price bookmarking for revisiting. I surprise how a lot attempt you set to create this type of fantastic informative web site.
Somebody necessarily lend a hand to help make significantly articles I may state.
That may be the first time I frequented your webpage and
thus far? I amazed together with the analysis you created to create this type of submit extraordinary.
Magnificent task!
It’s genuinely very complex in this busy life to
listen news on Television, therefore I only
use web for the reason, and take the latest news.
Amazing issues here. I amm veryy satisfied too look you article.
Thanks so much annd I’m havibg a lokk forward too contact you.
Will you pkease drp mee a mail?