How to Center Dynamic Text in a Specified Area

In a recent project of mine, users were allowed to choose from a list of phrases. The selected phrase then appeared in a text box. The problem was that if the text was too short it would sit there at the top of the box rather than being centered. Before I get into the code (which is pretty short), here’s a working example:
Download the source here

Continue reading "How to Center Dynamic Text in a Specified Area"

Clickable Button Inside a Draggable Movie Clip

I’ve noticed postings in a few different places asking “How do I get a button to work inside a draggable movie clip?” The answer, of course, is that you can’t. Once you attach an event handler that listens for the mouse, the movie clip will receive mouse activity rather than any button contained within. But there is a way to achieve the desired effect, and it’s easily done.

The trick is that you don’t place the code on the movie clip itself. Instead, create a button the same size as the movie clip and place it inside the clip on a layer below your buttons. If you don’t want to see the button, make it invisible by populating only the hit frame. Attach your movie clip’s drag code to the button and then place any other buttons you want inside the movie clip on a layer above your drag button.

This way, the user will be able to drag your movie clip when they hold the mouse button down anywhere on the mc except for over the other buttons. Check out the sample below or download it here to see how easy it is.

This is all the code that it takes:

container_mc.drag_btn.onPress = function() {

container_mc.drag_btn.onRelease = function() {

container_mc.btn.onRelease = function() {
	this._parent._parent.text_txt.text="\rclick #"+counter;