Create a Basic Animating Accordion Panel in Flash
Learning the Accordion
One of the most useful user interface constructs is the accordion panel. It allows you to stack various sections of your site and then expand and contract the sections when they’re clicked on. In this tutorial, we’ll create a basic animating accordion panel that can be used as the basis for a full Flash website.
1 [EXAMINE THE FILES]
Open the accordion folder (from the download files available at www.layersmagazine.com) and you should see two FLA files: The accordion.fla file is what you’ll need to open to start the tutorial, and the accordion_final.fla file is a finished version of the tutorial that you can use as a reference. There’s also another folder named gs, which contains an ActionScript animation library called TweenLite that we’ll use to do our animation.

2 [OPEN THE FLA]
Open the accordion.fla file in Flash CS4 (this tutorial will also work with Flash CS3 if you haven’t yet upgraded). On the Timeline, you’ll see two layers: The actions layer will hold all of our ActionScript 3.0 code for this project and the panels layer will contain all of the various sections for our site. The movie is 690 pixels wide and 355 pixels high with a frame rate of 30, and it’s set to publish for Flash Player 9, as we won’t be using any of the new Flash Player 10 features.

3 [DRAW A PANEL]
Select the first frame of the panels layer and select the Rectangle tool (R). In the Property inspector, remove the Stroke color (if there is one) and set the Fill color to #0066CC (blue). Drag out a rectangle on the Stage at any size, then in the Property inspector set the following: W(idth) 600; H(eight) 355; X 0; Y 0. (Note: Make sure the chain icon is “broken” next to Width and Height.) Control-click (PC: Right-click) on the rectangle and choose Convert to Symbol. In the dialog that appears, name it “panel1,” make sure that Movie Clip is the Type, and click OK.

4 [ADD A TEXT FIELD]
In the Property inspector, give the new movie clip an Instance name of “panel1.” Double-click on it with the Selection tool (V) to enter edit mode. Select the Text tool (T), set the Character Family to Myriad Pro (or another font—make sure it’s a clean, legible font, as it will be rotated 90°), enter Size (as desired), and Color (we chose white). Click on the Stage and enter the text, “Panel 1.” Switch to the Selection tool, open the Transform panel (Window>Transform), and set Rotate to 90°. Return to the Property inspector and set the type’s X property to 0 and Y to 9. Click on Scene 1 to return to the main Timeline.

5 [DUPLICATE THE PANEL]
Now we’ll duplicate the movie clip panel for each section of the site. In the Library panel, Control-click (PC: Right-click) on the panel1 movie clip and choose Duplicate. You’ll be prompted to give the new clip a name, so let’s call it “panel2.” Now drag an Instance of the panel2 movie clip onto the Stage, and in the Property inspector, position it at X 30 and Y 0. Give the clip an Instance name of “panel2.” (Obviously, if you were building a real site you could name the various clips based on what they contained.)

6 [MODIFY THE DUPLICATE PANEL]
Double-click on the panel2 movie clip to enter edit mode so you can customize this panel. With the Text tool, change the text to “Panel 2.” Then, select the rectangle and choose another color in the Property inspector. Go back out the main Timeline. Now follow the same steps to create two more panels. Offset the X property on each panel by 30 pixels—that means the third panel will have an X of 60 and the fourth will be X 90. Be sure to give each panel an Instance name, following the same convention as above.

7 [IMPORT TWEENLITE]
Select the first frame in the actions layer and open the Actions panel (Window>Actions). Enter the code shown here into the panel. These two lines of code import the TweenLite animation library so that we can use it. TweenLite is an ActionScript 3.0 library that makes animating with code extremely simple. All that’s required is a single line of code to create some really complex animations. There are other engines such as Tweener and gTween that would also work well for this tutorial. (Note: Make sure the gs folder is in the same folder as your FLA file.)

8 [SET LEFT AND RIGHT POSITIONS]
Add the code highlighted here into the Actions panel. In these four lines of code, we’re attaching some information to each of the panels that will help us when we need to animate them. The first property, lx, is the leftmost X position of the panel. The rx property is the X position for the panel when it’s on the right side of the movie. Notice how all of these values are offset by 30 pixels from one another. The ind property simply holds the index number of the panel.

9 [ADD CLICK EVENTS]
Now we need to set up the click events for each of the panels so that they can react when one of them is clicked. Add these next highlighted lines of code to the Actions panel. The first four lines sets up the click events for each panel. All of them will call a function named onClick that’s located at the bottom of the code block. When a panel is clicked, it will animate all of the panels to the correct position allowing the user to view the full contents of that panel.

10 [WHO WAS CLICKED?]
Since all of the panels will call the same function when they’re clicked on, we need to determine which one was clicked so we can animate the panels appropriately. We can easily get a reference to that clip by using the target property of the event object that gets sent to the function. Add this highlighted code into the Actions panel at the specified location to create a variable named “clicked,” which references the clip that was clicked on.

11 [LOOP THROUGH THE PANELS]
Now that we know which clip has been clicked on, we need to loop through all of the panels and animate them to the correct position. In ActionScript 3.0, the most common way to do this is by using a “for” loop. A counter variable is incremented each time the loop is run until it no longer satisfies the condition. Enter the highlighted code into the Actions panel at the specified location. Inside the loop we create a new variable named “mc” that references the panel clip based on the value of the loop counter i.

12 [ANIMATE THE PANELS]
Enter this highlighted code into the Actions panel at the location specified. First, we check whether the index of the current clip is less than or equal to the index of the clip that was clicked on. If it is, we need to animate it to the left. If not, it needs to be animated to the right. For each case, we’re using the TweenLite.to function to do the animation. The animation length is set to 0.5 seconds and we’re using an exponential ease-out effect. Both of these settings can be customized to change the feel of the animation (see Step 14).

13 [ADD CONTENT TO THE PANELS]
Test the movie by choosing Test Movie from the Control menu. Click on the various panels to see the nice animation effect. Now that the code is complete, you can start customizing the panels so that they contain actual content. Double-click on one of the panels to enter edit mode. Now you can start adding text, images, video, or anything else that you want on that particular panel. Check out the accordion_final.fla file to see an example of a finished panel.

14 [CUSTOMIZE TWEENLITE]
As mentioned in Step 12, you can change some of the values in the TweenLite function call to customize the animation effect. Try changing Expo.easeOut to Bounce.easeOut. This makes the panels bounce into place. Another interesting choice would be Elastic.easeOut, which gives it a springy, elastic effect. You can also adjust the length of the animation to achieve different results. To see the full list of customization options, check out the documentation for TweenLite at http://blog.greensock.com/tweenliteas3.

Visitor Comments »
Comment by Brandon Kastning | November 18, 2009 @ 7:25 pm
OK, one more question, pertaining specifically to this tutorial. Shouldn’t panel 1 also animate to the right when clicked? According to the info above, “The rx property is the X position for the panel when it’s on the right side of the movie.” Panel 1 has been given an rx value of 570.
So, shouldn’t it move as well? But, seeing how it doesn’t, what code needs to get plugged in so that it, too, can animate? (It may seem pointless, but trust me, it’s not!)
Comment by Jeff | November 20, 2009 @ 6:06 pm
The accordion.fla file will not open for me. I am using CS3 on a Mac.
I tried clicking on the file, no luck; and open from inside flash, still no luck.
What Am I doing wrong?
Comment by Kathy | November 21, 2009 @ 10:56 am
[...] click here to read more of this tutorial Share This [...]
Pingback by Create a Basic Animating Accordion Panel in Flash | Layers Magazine | November 23, 2009 @ 11:24 am
I was looking forward to trying this tutorial out, but when I try to open the downloaded files, I keep getting “Unexpected file format” come up. I’m using CS3 on a PC – any ideas? Thanks!
Comment by Sam | November 23, 2009 @ 12:24 pm
I have CS3 and it won’t open the files. It said it was for both.
Please respond as to why they might not open.
Don
Comment by Don | November 23, 2009 @ 1:05 pm
sigu up for a tutorial
Comment by Ronald | November 25, 2009 @ 6:45 am
Cant open the files – “unexpected file format”
Comment by casper | November 29, 2009 @ 1:24 pm
I have CS3 and it won’t open fof me iether? why is this? Spyros
Comment by spyros | November 29, 2009 @ 8:01 pm
Unexpected malformed
the file for download is corretc
Comment by liko | November 30, 2009 @ 4:14 am
Great tutorial!
I am having a little issue. In each of the panels I have placed a Dynamic Text field which I populate via XML. The issue is at run time I receive the following error:
#1034: Type Coercion failed: cannot convert flash.text::TextField@30ca9f89 to flash.display.MovieClip.at accordion3_fla::MainTimeline/onClick()Any idea on how to prevent this?
Comment by John Prosek | December 1, 2009 @ 8:19 am
Oh another note: The error only occurs when you click on the text fields.
Comment by John Prosek | December 1, 2009 @ 8:48 am
I’m getting the same error. The final version won’t even play.
Comment by Andrea | December 1, 2009 @ 6:01 pm
If you add an object or shape that is fixed (has no animation), I get an error: Error #1034. The script cannot change the shape into a MovieClip. Does every shape needs to be defined into the script?
Without it, it works fine.
Comment by Jasper | December 1, 2009 @ 11:33 pm
Tried to open files relating to “create a basic animated panel in flash” But all I get is “unexpected file format” Can you tell me whats going on? I have CS3 and this project is supposed to work in CS3.
Comment by spyros | December 2, 2009 @ 9:08 pm
I have two questions.
1) What would be the easiest way to have the tab area (not the whole panel) behave like a typical button with the “hand” mouseover to indicate a link? I know that “mc.buttonMode = true” makes the entire panel behave like a button, but I’m wondering how to do just the exposed tab portion. (In the old days, I’d make an invisible/hit area only button over just the tab. When I do this now, I get an error that prevents the AS from performing the function to move the clip.)
2) I can’t get my head around the functionality needed to make the current panel’s tab “close” that panel if it is clicked once more after it’s been opened… Essentially I want the panel’s tab to toggle it open/closed. I can fake it with an invisible panel, but I want to understand how the code would work for that.
Thanks for any help!
Comment by Mark Ross | December 3, 2009 @ 8:15 pm
You have to open all files in CS4 first and then save the files as CS3.
Comment by AP | December 4, 2009 @ 3:41 pm
Is confuse, where`s the offset properties for x positions?
Comment by irp | December 10, 2009 @ 10:22 am
Nice Tutorial, all is working well.
Just have one thing to say that you have forgotten to mention about the registration point, it needs to be on top left corner when you convert into a Movie Clip, otherwise it will not work properly.
Comment by earthflyer | December 12, 2009 @ 9:05 am
Don,
What is the syntax for a vertical accordion movement?
I see the syntax convention for left and right but what is the syntax for top and bottom, ty and by?Will this work?
about.props = {ty:0, by:400}
home.props = {ty:30, by:430}
Comment by Doug Marlowe | December 13, 2009 @ 12:47 pm
I have CS3 also and it won’t open the files. I tried making it by the directions above and the accordion didn’t work.
Sarah
Comment by Sarah Childers | December 16, 2009 @ 4:53 pm
This file will not open in CS3. Was it saved for CS3?
Comment by Ash | December 30, 2009 @ 9:39 am
hiiiiiiiiiiiiiiiiiiiii
Comment by bitch | January 4, 2010 @ 2:44 pm
very informative Tutotrial
Comment by saki | January 22, 2010 @ 3:26 am
I did the tutorial and my code is identical to the code in the tutorial.
When I click on the my panels, the tween is jerky and it doesn’t bounce. I copied my panels onto the “acordian_final” fla and it works just fine.
So I thought that maybe my code was off, so I copied the code from the “acordian_final” fla into my fla file and the tween is still jerky.
I don’t understand why my file isn’t working correctly. Help!
![]()
Comment by Kelly | January 27, 2010 @ 3:33 pm
Yeah, this non-working tutorial does NOT make me want to sign up for the magazine!!!
And even more frustrating that no one will respond. WHY leave an option to comment if no one is tracking comments???? You’d think a web design mag would know that.
Comment by Malapert | February 27, 2010 @ 3:16 pm
amazing i still have no idea about gs folder but it’s work and that amazing
thanks
Comment by SWiSHZOOM | February 28, 2010 @ 4:58 am
Leave us a comment

- Dragging an Object Between Documents
- TV Scanline Effect
- Trick to the Glossy Effect
- 3D Text
- Changing Type on a Path





Photoshop
Illustrator
Indesign
Dreamweaver
Fireworks
Premiere
Flash
After Effects
Lightroom
Acrobat














