PDA

View Full Version : custom accordion in AS3



Oshii
January 10th, 2008, 06:00 AM
Hello,

Hope this post doesn't feel too long for you guys to read. Ill try to keep it short, Ill describe the problem in the first paragraph below. I've attached my files with code.

Im trying to create a custom made accoridion menu. I thought I had it all working they way I wanted, but noticed one bug. When the menu-blocks slide up and down they don't return to the exact same position. Its not noticable at first, but the offset grows if you play around with the accoridion for a while.

The accordion is several boxes (mc: box, in the library), where each box knows of the box below it. When the box slides down it also moves the box below it which creates and accoridon effect. The mc: box, has a linkage to the file Box.as. The file: accordion.fla has actionsscript code on the first frame in the top layer named "actions", all the rest of the code is placed in the Box.as file.

I guess I know why the box positions become desynched, but Im not sure how to solve it. The problem (if I'm thinking correct here) is that the easing function never reaches the exact target position, so when its almost there it stops and the mask is moved the remaining distance but the box/boxes below which moves together with the mask stops where the mask left of. Since the mask and the boxes are located within different movieclips their y-positions aren't the same, so I have to calculate the differnce. Maybe Im just stuck in my old way of thinking but I just cant figure out a good way to solve it.

Ive tried different methods:
- to calculate the difference between where the mask is stopped and where it is placed afterwards.
- to round of the final y-position-value, because its always at a decimal of a pixel.
- to keep track of the parent box and place it just below the parent box's position, with an offset of the content width if the parentbox is expanded.
- to keep track of the starting position of each box, and then adjusting it to the starting position everytime it stops. If any of the above boxes are slid down though, there is an offset to the starting position, which I will also have to keep track of.
The second two approaches, which may have failed because of myself introducing bugs in the code, but they seem a bit far fetched imo, I have the feeling there is both an easier and better solution to it?

Any ideas are appreciated. Thanks!

Felixz
January 10th, 2008, 05:52 PM
i think u should redesign a bit ur buttons:
-delete old mask
-create empty sprite with.y=hdr.height
-set .mask property of content to that new mask
-make mask scripted; draw a rect starting from 0 and ending in content.height
-store variable responsible for mask's height
-use that variable to position subboxes (variable+this.y+hdr.height)
-this would be less cluttered and more optimized since many calculations are going away

dail
January 10th, 2008, 08:26 PM
I've made an accordion menu which you can take a look at here if you like; http://www.blog.noponies.com/archives/39

Oshii
January 11th, 2008, 01:52 AM
@Felixz Thanks for your tips! It helps. I will definitely clean up the code. This is more of a quick and dirty version to see if it works.

@dail Looks really nice. Ill have a look at your code, thanks for sharing!

adylevy
July 18th, 2008, 03:57 PM
you can check out a nice accordion written in as3 in my site :
http://www.adylevy.com/index.php/2008/06/09/accordion-class-flash-actionscript3-as3/

webechelon
October 17th, 2008, 05:42 AM
hi if any one want free tutorial for a accordion menu in flash like socsglobal.com pls contact me..... even i can provide u .fla source file... (Flash 8, no xml codes)

Regards,
Webechelon - Flash Development (http://www.webechelon.com) Website Design (http://www.webechelon.com)
http://www.webechelon.com

vginov
November 21st, 2008, 08:59 PM
Dear all
I am new to flash. I am just a PHP web developer.
I am designing a website with an accordion menu. All of my scripts are in AS3.0 where as the flash accordion component supports only for AS2.0. Is there anyone has an accordion component for AS3.0 or a code to create a custom accordion? If you have, please help me.

I took a look at

http://www.adylevy.com/index.php/2008/06/09/accordion-class-flash-actionscript3-as3/

The script is very nice and it meets my need but I am not able to understand the code because I am new to flash.

And I looked at the bellow one

http://www.kirupa.com/forum/showthread.php?t=285518

the accordion.zip file

It is very nice and a simple logic and I am able to understand but I am getting some error due to the action script external file
I used include “Box.as”

But it always gives me error

Can anyone please help me?

Thanks a lot

Felixz
November 23rd, 2008, 04:50 AM
Maybe you need import instead of include.