[AS3] "Complex Button" package

Seems I spend too much time coding menu groups of “complex buttons” (meaning buttons that may or may not animate, but remain selected (in down state) after clicked) - also seems the question gets asked quite a bit in many different. It’s not incredibly difficult, but I noticed I kept writing the same code over and over so came up with this package to make my life easier. Don’t know if I’d go so far as to call it a “framework”, but it’s sort of a loose interpretation of the Adapter design pattern that makes it easy to create groups of buttons with one that remains “down”.

Basically, all you have to do is create a class for your button type that extends MovieClip or Sprite and implements IComplexButton (in the download). All that class does is describe the visual states of your button (up, over and down) and can be as simple or complicated as you’d like. That button class is then “wrapped” in a ComplexButton instance which handles all events. Several of those ComplexButtons are then added to a Menu instance which keeps track of which item is selected and redispatches events so you can add event listeners directly to the menu instance…

Sounds more complicated than it is. All the user has to do is worry about the visual states of their buttons and everything else is taken care of…

Quick example here: http://www.onebyonedesign.com/flash/complexbuttons/

So for that I just used 3 button types and created 2 menu instances…

If interested, that example and all classes are in the download here: http://www.onebyonedesign.com/downloads/complex_buttons.zip

Hopefully that made some sense and helps out… Saves me coding time if nothing else… :slight_smile:

I download the example. Upon test it I have this error message :

Warning: 1090: Migration issue: The onMouseDown event handler is not triggered automatically by Flash Player at run time in ActionScript 3.0.  You must first register this handler for the event using addEventListener ( 'mouseDown', callback_handler).

The source of this error is from ComplexButton.as line#48, #57, #87, #91, #96, #99, #103, #109, and #113.

Hey Beebs,

A warning is all that is. In AS2 there was a designated event handler named “onMouseDown”. Flash is just trying to be nice and tell you that in AS3 that method no longer exists unless you define it yourself - which that script does. If it really bothers you, you can change the names of the different methods that give you that warning, but it really won’t cause any problems to just ignore it.

Incidentally, I made this a part of a package of user interface tools that may come in handy…
http://blog.onebyonedesign.com/?p=72
http://blog.onebyonedesign.com/?p=63

Hey devon. Still going strong I see :wink:

wicked work

No offence but isn’t it not that hard to code something like that, a simple if\else statement?

first function

{
If(bt_down.alpha = 1)
{
bt_down.alpha = 0
bt_down2.alpha = 1
}
else
{
bt_down2.alpha = 1
}
}

second
{
If(bt_down2.alpha = 1)
{
bt_down2.alpha = 0
bt_down.alpha = 1
}
else
{
bt_down.alpha = 1
}
}

I mean, thats just with two buttons more would get complicated but you get what im saying right/

bt down being the overlay your using over the main buttons (1 and 2) to make them appear down
I guess it might over complicate things making the functions alpha based, but thats how i would go about it.

No offence but isn’t it not that hard to code something like that, a simple if\else statement?

Offensive? NO. Missing the points? YES

@sekasi - yup… still out there swingin’… I see you’re all over the web as well… :slight_smile:

@saxx - as Beebs pointed out, the point of the package is to avoid writing code like that. One of the major selling points of OOP is code reusability… Sure you could write that same thing with minor changes in every project you do, but it’s much nicer to save production time by having it all done for you regardless of what properties you wish to change for selected items…

Thanks devonair :slight_smile: I now get the point of the package hes releasing. I always try to overcomplicate things :frowning: