…and especially enthusiastic about motion tweens in Flash…
In the previous blog entry, I linked to a new JSFL that automatically gives instance names to selected instances in a smart way. You can go read about and download the JSFL from this page. This entry shows you how to use this command along with some of the new features in Flash CS4.
Lets look at the finished file first. It’s not very pretty, but hey this is just something to learn from or whatever. Roll over the stars and they’ll tween.
Make sure you have Flash Player 10 installed to see the full animation: http://www.adobe.com/go/getflashplayer.
So this example uses the JSFL linked above, the new motion tweens to animate the stars, the deco tool to spray them on the Stage, tween instance to animate the stars when you roll over them, and a bit of ActionScript 3.0 to make things happen and change the alpha.
Download the FLA file (Flash CS4).
A fairly literal explanation of how this was created.
Before you star, make sure you have downloaded and installed the JSFL from this blog post .
star1 and click OK to name them.star2 and star3.star1parent for the star1 prefixed instances… and of course star2parent and star3parent for the other two. myFunction(star1parent, "star1_", MouseEvent.ROLL_OVER, item_rollOver1); myFunction(star2parent, "star2_", MouseEvent.ROLL_OVER, item_rollOver2); myFunction(star3parent, "star3_", MouseEvent.ROLL_OVER, item_rollOver3); function myFunction(target:DisplayObjectContainer, childPrefix:String, eventName:String, callbackFunction:Function):void { var targetDispObj:DisplayObject; for each (targetDispObj in target) { if (targetDispObj.name.indexOf(childPrefix)>-1) { targetDispObj.addEventListener(eventName, callbackFunction); } } } function item_rollOver1(evt:Event):void { evt.currentTarget.alpha = 0.5; holder.theTween.addTarget(evt.currentTarget); } function item_rollOver2(evt:Event):void { evt.currentTarget.alpha = 0.8; holder.theTween.addTarget(evt.currentTarget); } function item_rollOver3(evt:Event):void { evt.currentTarget.alpha = 1; holder.theTween.addTarget(evt.currentTarget); }
So that code basically looks for all the stars with the star1 prefix and sets the alpha then attaches the tween instance on rollover. The star2 gets a different alpha and the same animation on rollover, etc. Now you could have multiple tween instances with different name (theTween2, theTween3, etc) so a different animation occurs on rollover. You could neatly keep them all in the same holder so they’re all in the same place and off the stage.
That’s all there is kids. Ask your questions in the comments.
This blog specializes in the new motion model of Flash CS4, and is brought to you by team tween of Flash at Adobe. The blog will includes tips, techniques, and info on tweening in Flash using the Timeline and Motion Editor (as well as some stuff about motion runtime with code). From time to time, we might also talk about ActionScript 3.0. So if you're interested in tweens, this blog is for you. We also want to hear your feedback in the comments. All views expressed here are those of the authors, and do not necessarily represent the opinion or views of Adobe Systems Inc.

alan bigelow
April 2nd, 2009 at 3:46 pm
Hi–
Great tutorials! Unfortunately, I am having a problem with targeting multiple motion tweens in Flash CS4. I am using AS2 and attempting to change the visibility of eight separate motion tweens (visible false and then true). The tweens are masked, otherwise I’d make movie clips out of each one and turn their visibility on and off that way. I want to be able to affect each tween separately.
I have tried MANY angles on this, but only the first tween mentioned in the AS is affected, but the rest of the tweens are not. Is this something to do with CS4, which I am new to?
I am at a loss… Any suggestions? Many thanks!!!!
Jen deHaan
May 5th, 2009 at 3:41 pm
I forgot to link, but this is covered in a forum thread here:
http://www.kirupa.com/forum/showthread.php?p=2455640
güvenlik
May 21st, 2009 at 10:34 am
You can follow any responses to this entry through the RSS 2.0 feed. You can skip to the end and leave a response. Pinging is currently not allowed.
2 Responses to “Flash CS4 example: Spray Brush, Tween instance