Creating a button using only action script (MX)

I tried posting this once before, I will now try once again.

I enjoy the challenge of creating all sorts of things entirely with actionscript (quizes, games, movies, etc). It is not particularily useful but it can be very difficult and fun. It’s very satisfying to show someone an fla file with one empty frame and only an action attatched.

I have only been able to create buttons with actionscript by creating a movie clip - this.createEmptyMovieClip (“InstanceName”, depth) - and then specifying the fill and stroke.

I’ve always wondered what the script is for creating the actual button itself, instead of using a movie clip like a button. For instance, something like - this.createNewButtonInstance(“InstanceName”, depth) - this doesn’t actually work, though.

I’ve looked around before, and I can continue using movie clips if necessary, I just thought I’d ask. If anyone knows and would like to post it here, I would be very grateful.

hey capn,

i enjoy creating movies with scripts too. however, i find it very useful indeed!

buttons seem to be movieclips minus some functionality. they don’t have any unique properties or methods, and don’t seem to have a constructor method (short of new Button()) built in to flash.

since a button lacks access to a movieclips drawing api, attachMovie, duplicateMovieClip, etc. it would also be challenging to give it a graphical representation on the screen. you could still make it react by doing something like this:


b = new Button();
b.onMouseUp = function(){ trace("up");} ;
Mouse.addListener(b);

i’d say keep using movieclips and enjoy all the extra methods available.

why limit yourself? ; )

Yeah, I agree. I probably will continue to use movie clips. It just always bugged me that I didn’t know how to do AS for a button.

Thanks a lot for the help, I will store that little tidbit away in my brain, so I can wow people when they realize the depth of useless information I hold!

There’s a fla at bit-101. It’s a bit old, I’ll look for it, give me a minute.

It’s the 10th of July 2002.

That’s very cool. That might start the old inpiration pot brewing.

Thanks for the link.