~::Cheery Dreary Blog::~

Monday, December 8, 2008

Brown paper packages tied up with string...

...these are a few of my FAVORITE things...









Yes. Pure Geekery. And it's not even impressive geekery if you're "in the know" but I loves it. (Note, no pictures of Javascript... of which I have yet to found love for.)

Labels: ,


Wednesday, December 3, 2008

Knowing your roots

The best way to grasp something is to explain it to somebody else. SO - I just learned this today and thus this blog is my "explanation to somebody else" (that might be useful to somebody in a google search one day.)

With AS3 came the elimination of "root". I had just learned AS2 roots and then boom... you've got to start all over because there ain't know root no mores!

Basically - in AS2 you can put all of your code on frame 1 of the main timeline - including your functions and global variables. Then if you make nested movieclips (as I do.. nested with nested within nested) you could call up to the function or movieclip in the main timeline by prefacing it with "root." Like so: "root.book_mc.gotoAndPlay("page1");"

Pretty simple once you got the hang of it. It was rather like a man in a sewer calling up to his buddy on the street level to say "Hey, throw me down a bottle of water." Or "Hey, can you call my wife and tell her I'll be late to dinner?"

Well now in ActionScript 3 there is no "root." (Well, actually there IS a root but it does something different that I just don't understand.) Instead you use "MovieClip(this.parent)". Or "MovieClip(this.parent.parent)" if you're nested two deep. (Or MovieClip(this.parent.parent.parent.parent.parent)...etc... although I don't know how far down you can drill before everything just explodes.)

For example - let's say that I have a MovieClip called "book_mc" and inside of that I have a MovieClip called "pages_mc" and inside of THAT I have another MovieClip called "words_mc". Now let's say that inside of "words_mc" I have a MovieClip called "button_mc". And when I click on this button I want the book to go and play it's animation of the book closing. (This blog would be helpful with graphic explanations... but alas... no graphics for you!)

In my code I would first clarify where exactly I was by using a trace statement (within an MouseEvent.CLICK function) like so: "trace (this.parent.name)" This is saying, "Hello button upon which I have just clicked... what is your Mom's name?" (Where "trace (this.name)" would yield a result of "button_btn", by putting the "parent" in there I would instead yield "words_mc".)

OK so now I know that I'm inside of words_mc. And I already know that words_mc is inside of pages_mc which is inside of book_mc. So in order to tell the book to close I would have to write something like "MovieClip(this.parent.parent.parent).gotoAndPlay("closeBook")". In order to call a FUNCTION on the main timeline I would write something like "MovieClip(this.parent.parent.parent).functionNameHere();"

These periods, btw, are actually "dots" and what I'm doing here is called "dot syntax."

Got it now?? Good. Instead of the man in the sewer this is more like some annoying guy at a mixer who is REALLY INTO genealogy, "Hi, who's your Mom? And who is her Mom? And what was her Dad's name? And his Dad? Yeah, I was wondering, could you please ask your Great Great Great Grandfather to send a message to Marty McFly? Awesome!"

(But I don't mean to confuse you... we're not actually time travelling. It's more like the man in the sewer saying, "Hey, I'm on this ladder, and this ladder is attached to a truck, and the truck is on the road and the road is in the universe and we are ALL in the Matrix!")

Damn! I better understand this now.

(Also check this FlashKit.com forum post for another, cleaner, way to do it in a more OOP way.)

Labels: , ,