If you are working with multiple layers of MovieClips, each with their own ActionScript (trust me, with dynamic projects, you can end up in a situation where MovieClips have minds actions of their own) you might come across a situation where you need to access a variable or another MovieClip from the MovieClip that owns it (as in it’s parent) or even two or more above.  (If you need to skip all the nested MCs and access a variable on the now-depricated _root read this article)

This is actually quite easy with a method called parent, utilizing the hierarchy of your MovieClips to access variables from any number of levels away from your current execution realm.

To access a variable – let’s call it myVariable – from one level up in your tree, use this:

trace( MovieClip( parent ).myVariable );

Similarly, to access a variable two or more MovieClips up in the tree, nest the parent calls accordingly.

trace( MovieClip( parent.parent ).myVariable );

You can do this ad-infinitum to the root of the whole project if you so desire, but in this case, again, I’d recommend that you read the article mentioned above.

To access other MovieClips, the process is very much the same, except instead of a variable name, you would use a MovieClip’s Instance Name followed by the property you wanted to adjust, as such:

MovieClip( parent ).myMovieClip.visible = true;

-or-

MovieClip( parent.parent.parent ).myMovieClip.gotoAndStop( 1 );

etc.

Hope this helps someone,

Cheers,

~/A\V/

Tagged with:
 

Bit of a longer hiatus from this blog than I had imagined – Orange has kinda been taking up a LOT of time lately (I have quite a few articles that are non-tech related that need to be edited and then I will post) – but here’s an ActionScript Quickie:

If you need to work with a variable from the Main Timeline (formerly _root in AS2) in another MovieClip in the same project, you can do this by using the “root as MovieClip” property.  This allows you to load elements from what was _root into your current working MC. (If you only need to go one or two levels up, read this article)

Quick and dirty, in your new MC, you can test this functionality with the following:

trace((root as MovieClip).myVariable);

Replace “myVariable” with the variable you wish to access from the Main Timeline, of course.

Digging a little deeper, we can assign this variable to a more… suitably accessible medium by using the following (assuming that the variable type is String for this example, use the typecast that you need in a situation):

var myNewVariable:String = (root as MovieClip).myVariable;

Again, replace “myVariable” (and variations therein) with your own names.

Hope that this helps someone!

Cheers,

~/A\V/

Tagged with:
 

From time to time you might find it necessary to track the cursor when working with Flash.  Fortunately, this is fairly easy.

As with all things Flash when dealing with values, you should create the variables beforehand so as to prevent loads of errors when compiling.

Here’s the code, it uses an Event Listener:

var yCoord:Number = 0;
var xCoord:Number = 0;

stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove); function mouseMove(event:MouseEvent){
yCoord = mouseY;
xCoord = mouseX;
} );

yCoord and xCoord would be your mouse coordinates.  This Event Listener is called on on the stage to ensure that you get the coordinates whenever the mouse moves across the stage.  In the event that you would like the mouse to be tracked only on a particular movie clip, exchange the “stage” identifier for the identifier of the movie clip you want to track the movements on.

Hope this helps someone…

/A\V/

Tagged with:
 

Today I was attempting to make a movie clip that would fade in on rollover and fade out on rollout.  The problem that I had, however, was that there are buttons placed inside this mc, and if you in turn mouse over them, it causes the whole thing to quickly fade out/in all over again – for whatever reason – making a blinking mess.

Anyway, after a rather frustrating search across google, I came across some interesting information.  There is, now, in AS3, a property called Mouse.cursor, and using it, along with event listeners, you can force the mouse cursor to be whatever you want it to be!

It has a total (that I know of) number of five different properties: ibeam, hand, arrow, button, and auto, and is formed as such:

Mouse.cursor = “ibeam”;
Mouse.cursor = “hand”;
Mouse.cursor = “arrow”;
Mouse.cursor = “button”;
Mouse.cursor = “auto”;

And you would put whichever one you need inside your rollover event listener.  Be sure to set it back to auto after you roll out, otherwise you could end up with a very confusing UI experience!

Hope this helps someone!

/A\V/

Tagged with:
 
Pro Palma Deus Unus