Skip to main content
January 15, 2009
Question

Creating a button, then filling it with a box in AS 2 ?

  • January 15, 2009
  • 8 replies
  • 899 views
Hello guys,

I'm a young designer with only a year of pro experience in flash design, and I already made some good progress during that time.
however, I'm the only one in my company with some knowledge of flash and AS, and today I'm encountering a problem that long hours of research did not solve.
I'm working on some banners for a marketing campaign (already did several without problems), but I've had a very, very stupid idea : automatizing the clicktag button creation.

what I need is a script that creates a button the size of the stage, then creates a transparent fill inside and attaches some code on release, etc, for that button to work.

what I have achieved so far : a working script creating a fill in a movieclip and using it as a button.
the only little issue is that for the companies we work with, it HAS to be a button, and it HAS to have the code attached to it directly with an on (release) function.

I've tried embedding the movie clip in a button, resizing the button, trying to refresh it, but it seems like it only keeps the hit zone it had at creation, and if the button is empty, then there's no hit zone :s

I'd love some help on this, folks, and if someone around the world is willing to criticize my work, I'm attaching my actual code to this message 🙂
This topic has been closed for replies.

8 replies

kglad
Community Expert
Community Expert
January 21, 2009
you're welcome.
kglad
Community Expert
Community Expert
January 16, 2009
then follow the directions i gave for creating a transparent button.
January 21, 2009
resizing a button containing a transparent box worked perfectly.
I was trying to draw the box instead of starting with an existing one, that was a more complicated idea ^^

thank you.
kglad
Community Expert
Community Expert
January 16, 2009
you're wrong on both points. but if you're satisfied with those conclusions, good luck.
January 16, 2009
actually I'm very dissatisfied, but I don't have any idea on how I'm going to work around that issue ^^
I'm not someone content with something unfinished.
kglad
Community Expert
Community Expert
January 16, 2009
you can't use an empty button. create a fill with alpha=0 for all frames.
January 16, 2009
that's what the code in the movieclip does : creating a fill the same size as the stage to serve as the button.

but anyway, I've come across a piece of adobe documentation stating that runtime creations don't accept on event handlers, so I guess what I try to make is impossible since I can't use anything else than a button and a button accepts only on event handlers, nothing else :(
kglad
Community Expert
Community Expert
January 16, 2009
that doesn't make sense: you have a (resized) true button and when you mouseover it you fail to see the mouse pointer change to indicate you're over a button?
January 16, 2009
sorry if I'm unclear.

my current architecture is :

- empty button (with one frame covering all states) [empty movieclip]

on the button is the on (release) code.
on the first frame in the movieclip is the draw box code.

when my swf loads, the button is empty, then, the movieclip is filled with a stage-size box, BUT the hitzone of the button containing it doesn't change.
kglad
Community Expert
Community Expert
January 16, 2009
what do you mean by the "click zone" and the "hit zone"?
January 16, 2009
the "click zone" is, for me, the automatically created stage-size box with a fill, while the "hit zone" is the actual active zone of the button (changing cursor to hand and triggering the on (release) script).

if I manually create a fill in the movie clip embedded in the button, it counts as hit zone from the start, but if I have it created by a script, or resize the button, the hit zone isn't "updated", as if it were fixed at runtime and unmodifiable.

thanks for your help :)
kglad
Community Expert
Community Expert
January 15, 2009
no. just resize the button:

btn._width=Stage.width;
btn._height=Stage.height.
January 15, 2009
I tried that this afternoon as well, the button gets resized and the click zone is showing (at the correct size, stage size), but somehow the hit zone isn't updated, and I have no clue as to why :s
kglad
Community Expert
Community Expert
January 15, 2009
create a transparent button in the authoring environment and put it on-stage and give it an instance name and attach your code to your button.

then use a function to size your button and to define the variables used in the mouse event.
January 15, 2009
you mean resizing a button with a transparent box inside instead of drawing the box ?
It could work, I'll try tomorrow.

thanks !