Read More Ninja Action!

Flash Quick Tip: How to make a MovieClip behave like a button with the mouse cursor

Hi everyone, just a quick tip.

Have you ever wanted to use a MovieClip on the stage as a button? It happens a lot, sometimes you don't want to animate both artwork and a button around and you just want to use the MovieClip itself as the button. You can assign your listeners and everything on the clip, but when you preview the movie the mouse cursor doesn't turn into the little hand as you roll over it. It makes it hard for the user to know that area is interactive. Here's how you fix it!

First, make a MovieClip on the stage and give it the instance name of myButton. Then, on the timeline, enter this code:

myButton.buttonMode = "true";

Now Flash knows to treat your clip like a button as far as the mouse cursor is concerned. Enjoy!
Read More Ninja Action!

Getting the "parent" property to work in Actionscript 3. Mom? Dad?!

Hey everyone!

Today I'll be helping you with a quick tutorial on using the "parent" property in Actionscript 3. If you're used to how things worked in AS2 you know that you can no longer refer to the parent of a clip with this simple notation:
myClip.parent.parent.parent.myMethod();
The compiler is more strict and so they've changed the syntax a bit. I want this to be a beginner's tutorial so I won't go into detail about that, let's work on the new way to do things!

First, I've made a movie with a clip on the timeline. I wrote a function on the mail root level of the timeline that looks like this:
function traceParent():void
{
trace("You've succesfully called on the parent!");
}
Easy, just a trace statement to see if what we code inside the clip is correct. Now, put a clip on the stage and INSIDE the clip put this script:
myButton.addEventListener(MouseEvent.CLICK, callOnParentClip);

function callOnParentClip(ev:MouseEvent)
{
(this.parent as MovieClip).traceParent();
}
Pretty easy! Above the content inside this clip, make sure you make a button called myButton to call this function. The key line is here:
(this.parent as MovieClip).traceParent();
You can see that now we have to cast the clip as a MovieClip specifically. What about if we have a clip more than one level deep? This is how you would handle that:
(this.parent.parent.parent as MovieClip).traceParent();

Very simple. Check out the source below for an example clip using this technique, and happy coding!

Sample (AS3, Flash CS4)