Be a Supporter!
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
AS: Hierarchy. Nov. 23rd, 2005 @ 05:37 PM Reply

AS: Main

AS: Hierarchy

Sit down class. Today I will teach you about Flash's built-in hierarchy. Yes, Ralph?

Ralph: "What is Flash, ms. Hoover?"

Shut up Ralph, that's none of your business. And stop eating boogers. What, Lisa?

Lisa: "Ms. Hoover, what is hierarchy?"

Hierarchy is a kind of structure, which uses words such as parent and child to describe relations between objects. In Flash, this structure is also used to store objects in a clean and ordered manner. This means you can structure your Flash work by keeping objects nested inside other objects.

When you place object A inside object B, A is a child of B, while B is the parent of A.

Ralph: "Ms. Hoover! Ms. Hoover! Is my booger my child?"

Shut up, Ralph.

Lisa: "Ms. Hoover, I can't see how this is related to Actionscript."

Then again you're just a snotnose kid, Lisa. You aren't even supposed to know what Actionscript is. Anyway, I was just about to get to that.

When you use AS, you need to be able to refer from one object to another, to make them interact. To do this, you have to know of certain parts in coding.

Names
Names are crucial when you need to keep track of objects. It's pretty simple really, if you don't know an object's name, how would you refer to it? If you place an object on the stage manually, there is a box in the Properties panel where you can enter the instance name of the object.
If you place an object on the stage via Actionscript, you will need to give it a name at the point of creation. You can also record it's target path to a variable, to keep a "shortcut" to it.

. (Dot syntax)
Using dot syntax is an essential part of Actionscripting.
A dot in the code is used to access a child of whatever is right before the dot. For example, if you write mc1. you have "entered" mc1, and can access all of it's children. In this example mc2 is a movie clip inside of mc1, therefore a child of mc1. This means that to access mc2, you have to write mc1.mc2. So, if you want to access the _x value of mc2, you have to write mc1.mc2._x. Get it?

_root
The root is the movie clip we often refer to as "main timeline", in other words the top-level movie clip which contains everything else. Call it Eve if you wish.

Eve: "Me?"

No, not you. You're in the wrong classroom, by the way.

If you open a new Flash document, draw something and convert it to a symbol, this symbol automatically becomes a child of the root movie clip. To refer to the root, use "_root." (Don't forget about the underscore). This is called an absolute path.

A negative thing about using _root is that it can have unwanted results when you load the .swf into another movie, because in that case the _root automatically gets moved to the parent .swf.

_root should be used if you are inside a child, grandchild, etc. of the root, and wish to access another child, grandchild, you know the drill, of the root. However, if you need to access another object that is not an heir of the object you are in, but in the same branch, that is, if you don't need to pass through the root to access it, you would rather use:

_parent
It's as simple as it sounds. It accesses the parent of the object you're on. See this picture for a visual explanation. _parent and this (see below) are used for so-called relative paths.

this
Yeah, that's right. This. The object on which you are. Many times, this is not needed though. For example, _x = 10 is just as good as this._x = 10. There are some times though, when this comes in handy. One reason to use this is simply to improve readability. Here's two more examples:

When you use the method function.call(), you have the parameter thisObject. It is the object that the word this in the function will refer to. Here you might want to use the object you're at, but excluding this would leave nothing, which does not suffice as a parameter.

This code on the main timeline will set the _root's _x to 100, since it doesn't use this:
ball.onEnterFrame = function () {
_x = 100;
};

While this would refer to the object "ball" inside the root:
ball.onEnterFrame = function () {
this._x = 100;
};

It should also be mentioned that to my knowledge, buttons can't be parents. Of course they can be a child of a movie clip, but just consider them impotent (ask your mother) when it comes to parenting. In fact, that's a bit of a lie, because they can contain movie clips and other buttons, but it's children can't be targeted with Actionscript. Let's just call them foster parents.

Arrays are an exception from the dot syntax. Read AS: Arrays by Denvish for more info on that.

Here are some targetting examples to practice on, just to see if you got the hang of it.
How would you refer to:

- mc2, a child of mc1, a child of the root, which is where you are?
- mc3, a child of mc2, a child of mc1, a child of the root, which is where you are?
- mc2, a parent of mc3, which is where you are?
- mc3, a child of mc2, a parent of mc4, which is where you are?
- mc5, a child of mc3, a child of mc1, a child of the root, a parent of mc2, a parent of mc4, which is where you are?

Oh well, that's all for today, kids. Have a nice... Oh, they're gone.

... Ralph? Are you still here? Since you are, I could always tip you about the Target Path button. It's right on top of the Actionscript panel, and you can use it if you are too stupid, or too lazy, too do what this lecture was all about. It was about hierarchy, Ralph. Stop picking your nose.


BBS Signature
JPI
JPI
  • Member since: May. 9, 2005
  • Offline.
Forum Stats
Member
Level 21
Blank Slate
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 05:44 PM Reply

Very nice, and some humor to learning actinoscript.

And now i can link this to n00bs.

Didn't learn anything new but very throughly explained.

Nice one.

JPI


SIG YOINK!

BBS Signature
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 05:46 PM Reply

Thank you, Ralph.


BBS Signature
Drake-SI
Drake-SI
  • Member since: Mar. 7, 2005
  • Offline.
Forum Stats
Member
Level 21
Programmer
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 07:08 PM Reply

Lol, I laughed, I cried, I learned =-P

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 07:13 PM Reply

At 11/23/05 07:08 PM, Drake_SI wrote: Lol, I laughed, I cried, I learned =-P

Then I have fulfilled my purpose on this forum =D

Thankyousir.


BBS Signature
Thomas
Thomas
  • Member since: Feb. 14, 2005
  • Offline.
Forum Stats
Member
Level 13
Musician
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 07:25 PM Reply

Don't copy names from the Simpsons please :(


wat
a compessor wil raise the volume while lowering the db - chronamut

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 07:28 PM Reply

At 11/23/05 07:25 PM, -Thomas- wrote: Don't copy names from the Simpsons please :(

Hey, it's just a gag, no seriousness. The "humour" was just a side-kick to keep you interested in the somewhat boring nag about hierarchy.


BBS Signature
Blaze
Blaze
  • Member since: Aug. 4, 2005
  • Offline.
Forum Stats
Member
Level 22
Programmer
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 07:30 PM Reply

At 11/23/05 07:08 PM, Drake_SI wrote: Lol, I laughed, I cried, I learned =-P

Haha. Me too!

ditto.

Very neat tut, Rantzien!

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 07:35 PM Reply

At 11/23/05 07:30 PM, Darkfire_Blaze wrote: Very neat tut, Rantzien!

Thank you. =)


BBS Signature
JD77
JD77
  • Member since: Mar. 30, 2005
  • Offline.
Forum Stats
Member
Level 17
Blank Slate
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 09:14 PM Reply

nice tut for noobs lol and nice "humor" lol. something made me...lol


*User Page under construction*

BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Hierarchy. Nov. 23rd, 2005 @ 10:40 PM Reply

At 11/23/05 05:37 PM, Rantzien wrote: . (Dot syntax)

great tutorial rantzien, but i would like to expand a bit on this:

[] - Array syntax
often, youll want to reference a dynamic object (one in which the name is called by a variable). let us pretend, ralph, that youve lined three of your boogers up on the table, and lovingly named them "booger1", "booger2", and "booger3", respectively. now, if someone were to ask you "what is an easy way to call all of these boogers?", you could say:

for (i=1; i<=3; i++){
_root["table"]["booger"+i].doAction();
}

the syntax looks similar to an array because you can consider a stage set up as an array. the _root houses many objects, all stored in the _root "array". one of these objects (objecta), may be parent to 3 children objects, stored in the _root["objecta"] array.

one final good use for this is the for...in loops, where you reference a parent object, and it will return all objects in that array. the following code will find all of the snotnosed kids in ms hoovers class, and make them behave:

for (i in _root["hooversclass"]){
_root["hooverclass"][i].behave();
}


BBS Signature
Guy-Fawkes
Guy-Fawkes
  • Member since: Aug. 1, 2002
  • Offline.
Forum Stats
Member
Level 07
Blank Slate
Response to AS: Hierarchy. Nov. 24th, 2005 @ 01:12 AM Reply

Excellent Advice. You should make more...

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Nov. 24th, 2005 @ 01:32 AM Reply

At 11/23/05 09:14 PM, JD77 wrote: nice tut for noobs lol and nice "humor" lol. something made me...lol

Thanks

At 11/23/05 10:40 PM, authorblues wrote: great tutorial rantzien, but i would like to expand a bit on this:
[] - Array syntax

Thank you for that addition. I knew I had forgot something.

At 11/24/05 01:12 AM, Guy_Fawkes wrote: Excellent Advice. You should make more...

Thankyou


BBS Signature
authorblues
authorblues
  • Member since: Jun. 21, 2005
  • Offline.
Forum Stats
Member
Level 12
Blank Slate
Response to AS: Hierarchy. Nov. 24th, 2005 @ 01:41 AM Reply

At 11/24/05 01:32 AM, Rantzien wrote: Thank you for that addition. I knew I had forgot something.

you didnt forget it. you just brushed it off with a redirect to AS: Arrays. unfortunately, denvish didnt exactly cover how the timeline sets itself up as an array, so i figured id answer the question. overall, your tutorial covers the most important thing for a new programmer to learn.

writing these AS threads, we often take for granted how far we have already come. hierarchal setup is something that makes sense to us, but so often, these simple things are hard for up-and-coming programmers to grasp, and as far as the bare-bones of programming, this is one of the first things to learn.

and for doing the dirty work and actually typing this up, i commend you.


BBS Signature
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Nov. 24th, 2005 @ 01:52 AM Reply

At 11/24/05 01:41 AM, authorblues wrote:
At 11/24/05 01:32 AM, Rantzien wrote: Thank you for that addition. I knew I had forgot something.
you didnt forget it. you just brushed it off with a redirect to AS: Arrays.

Actually I did forget it, I was just thinking about simple array access when I wrote that =)

unfortunately, denvish didnt exactly cover how the timeline sets itself up as an array, so i figured id answer the question. overall, your tutorial covers the most important thing for a new programmer to learn.

Yeah, the array access isn't crucial for learning hierarchy, but when it comes to targetting, which this tutorial was blended a bit of, then it can come in pretty handy.

writing these AS threads, we often take for granted how far we have already come. hierarchal setup is something that makes sense to us, but so often, these simple things are hard for up-and-coming programmers to grasp, and as far as the bare-bones of programming, this is one of the first things to learn.

and for doing the dirty work and actually typing this up, i commend you.

Yeah, thanks.

Gotta go


BBS Signature
GuyWithHisComp
GuyWithHisComp
  • Member since: Nov. 10, 2005
  • Offline.
Forum Stats
Member
Level 28
Blank Slate
Response to AS: Hierarchy. Nov. 24th, 2005 @ 02:06 AM Reply

At 11/23/05 09:14 PM, JD77 wrote: lol

lol


BBS Signature
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Nov. 24th, 2005 @ 05:31 AM Reply

At 11/24/05 01:52 AM, Rantzien wrote:
At 11/24/05 01:41 AM, authorblues wrote: writing these AS threads, we often take for granted how far we have already come. hierarchal setup is something that makes sense to us, but so often, these simple things are hard for up-and-coming programmers to grasp, and as far as the bare-bones of programming, this is one of the first things to learn.

and for doing the dirty work and actually typing this up, i commend you.
Yeah, thanks.

Gotta go

What I meant to type here before I realized my bus was about to leave (which I by the way missed =( ), was that when I finished this tutorial I browsed around to see if I forgot anything, and I couldn't find one half-decent tutorial about it! The best I could find was in the Help document of Flash, and that wasn't really a tutorial on it either.

At 11/24/05 02:06 AM, GuyWithHisComp wrote:
At 11/23/05 09:14 PM, JD77 wrote: lol
lol

Stop lolling in my thread =D
Oh, and happy birthday! *Hands over cake* I drooled a bit on it, hope that's ok.


BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Hierarchy. Jan. 7th, 2006 @ 01:37 PM Reply

Maybe you could do a little about _global

for all the really sad people out there :D

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Jan. 7th, 2006 @ 01:58 PM Reply

At 1/7/06 01:37 PM, T-H wrote: Maybe you could do a little about _global

for all the really sad people out there :D

That's not a bad idea, maybe I will.

Some day.

BBS Signature
liam
liam
  • Member since: Dec. 11, 2004
  • Offline.
Forum Stats
Member
Level 22
Blank Slate
Response to AS: Hierarchy. Jan. 7th, 2006 @ 02:05 PM Reply

At 1/7/06 01:58 PM, Rantzien wrote: That's not a bad idea, maybe I will.
Some day.

Lazy ass mo' fucker.

_global is an identifier, it makes the preceeding instance a global variable/class/etc which basically means it can be used anywhere in the Flash. For example, I have a class that adds the variables "mouseHeld" (when the mouse is held down), "mouseX"/"mouseY" (the AS3.0 names for _xmouse/_ymouse), "mouseSpeed" (mouse speed) and "mousePosition" (an array with the mouse _x and _y). Each of these variables is accessible anywhere in the Flash, not just where they are defined (where a new instance of the Class is created). The class is:

dynamic class MouseControl extends Mouse {
public function MouseControl() {
var mouseListObj:Object = new Object();
mouseListObj.onMouseDown = function() {
_global.mouseHeld = true;
};
mouseListObj.onMouseUp = function() {
_global.mouseHeld = false;
};
mouseListObj.onMouseMove = function() {
_global.mouseX = _root._xmouse;
_global.mouseY = _root._ymouse;
var curMousePos:Array = [mouseX-mousePosition[0], mouseY-mousePosition[1]];
var curMouseMath:Number = (curMousePos[0]*curMousePos[0])+(curMouseP
os[1]*curMousePos[1]);
_global.mouseSpeed = Math.sqrt(curMouseMath);
_global.mousePosition = [mouseX, mouseY];
};
Mouse.addListener(mouseListObj);
}
}

and yeah, I use it all the time.

That's basically it - official documentation here.


Sup, bitches :)

BBS Signature
Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Jan. 7th, 2006 @ 03:09 PM Reply

At 1/7/06 02:05 PM, -liam- wrote: Lazy ass mo' fucker.

No objection =P

description

Thanks =)

class

That's a useful class. I think I will make one too. =)
Gonna watch Gangs of New York now


BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Hierarchy. Jan. 7th, 2006 @ 03:12 PM Reply

At 1/7/06 03:09 PM, Rantzien wrote: Gonna watch Gangs of New York now

Good film. too long though : \

Rantzien
Rantzien
  • Member since: Jan. 27, 2005
  • Offline.
Forum Stats
Member
Level 15
Blank Slate
Response to AS: Hierarchy. Jan. 7th, 2006 @ 03:28 PM Reply

At 1/7/06 03:12 PM, TimHeasman wrote:
At 1/7/06 03:09 PM, Rantzien wrote: Gonna watch Gangs of New York now
Good film. too long though : \

=)

Is that a permanent name change?


BBS Signature
T-H
T-H
  • Member since: Jan. 7, 2004
  • Offline.
Forum Stats
Member
Level 40
Blank Slate
Response to AS: Hierarchy. Jan. 7th, 2006 @ 03:32 PM Reply

At 1/7/06 03:28 PM, Rantzien wrote: =)

Is that a permanent name change?

I've been meaning to give it a try for a while. figured I would tonight because I'm sick of people calling me T-H, just call me Tim : \

So far, I don't really like the look of it though, so we'll see :D

WolfAkela
WolfAkela
  • Member since: Dec. 19, 2005
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Hierarchy. May. 9th, 2007 @ 09:45 AM Reply

Really good read, I actually laughed. XD I never really understood the use of _parent until now. Thanks!

ChilliDog
ChilliDog
  • Member since: Feb. 16, 2007
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to AS: Hierarchy. May. 25th, 2007 @ 02:26 AM Reply

At 11/23/05 07:08 PM, Drake-SI wrote: Lol, I laughed, I cried, I learned =-P

That pretty much says it all. Thank you so much, this is helping me out a lot!


AS: Main

Don't read this sentence.

rickyboyce
rickyboyce
  • Member since: Jul. 9, 2007
  • Offline.
Forum Stats
Member
Level 08
Blank Slate
Response to AS: Hierarchy. Aug. 21st, 2007 @ 06:34 AM Reply

heyy thanks heaps for that i learnt heeaps!!!
i learned what a parent was and how it works and also what this. means!!:):):):):)
cheers


account moved, delete this account tom...please lol

Zeppekk
Zeppekk
  • Member since: Jun. 28, 2005
  • Offline.
Forum Stats
Member
Level 13
Blank Slate
Response to AS: Hierarchy. Jul. 27th, 2008 @ 03:04 AM Reply

At 8/21/07 06:34 AM, rickyboyce wrote: heyy thanks heaps for that i learnt heeaps!!!
i learned what a parent was and how it works and also what this. means!!:):):):):)
cheers

You didn't know what a parent was?

Are you a Test-Tube baby?

headphenomenon
headphenomenon
  • Member since: May. 1, 2009
  • Offline.
Forum Stats
Member
Level 13
Programmer
Response to AS: Hierarchy. Jun. 18th, 2011 @ 11:10 AM Reply

Very informative, very funny.


06-17-11: User of the Day
07-25-11: 1500th Post
08-09-11: Level 13!