Moving from Flash AS2 to Flash AS3: Paths

Tags: , , ,

A series of helpful Flash tutorials to get you feeling comfortable using Actionscript 3.0.

Getting Started with Understanding Paths Within AS3

As a Actionscript 2.0 programmer, one of the first hurdles to overcome when first using Actionscript 3.0 was _parent and _root. They’ve respectively changed to parent and root and they don’t entirely work as intended.

Currently, using parent the way it was used in Actionscript 2.0 will produce a compiler error as Actionscript 3.0 is a bit pickier about moving up paths. It uses class inheritance instead of the old prototype inheritance. It was designed to dispatch events, use listeners, pass variable that point to objects, all that other good stuff. However, that is not necessarily for everyone especially if you simply use Flash as an animation tool.

Here is a simple fix I learned from Bryan Grezeszak and it doesn’t involve complex event dispatching. Simply create a variable that stores the parent path and use that instead. By doing so, you are compromising the language and avoid getting wrapped up in a complete workaround only to find more bugs and errors.
// declare a variable that is parent
var newParent = parent;
// apply that instead of just using the command parent itself
newParent.gotoAndStop(2);

I tried this and it works like a charm and you can apply the same thing to root.

If you found this post useful, I would love to hear from you. All suggestions are welcomed.

Related Posts

CASA Lib

CASA LIb’s FrameUtil: Extending the Functionality of the Flash Timeline

CASA Lib ArrayUtil

CASA Lib’s ArrayUtil: Sorting, Searching and Manipulation of Arrays Made Easy

AS3 Library External Resource

How To: Implement an AS3 Library into Your Flash Environment

ActionScript 3 Logo

Moving From AS2 to AS3: A Handy List of Resources

5 Comments

  1. Eder Fortunato

    03.31.2008

    Reply

    test this:

    MovieClip(parent).gotoAndStop(2);

    Can be used for 2 parent:

    MovieClip(parent.parent).gotoAndStop(2);

  2. flashcrobat

    04.11.2008

    Reply

    cheers maestro, simple quick fix, that’s how I like it ;)

  3. Sjoerd

    07.31.2008

    Reply

    Can’t we just do it like this and keep our good old underscore?!
    // declare a variable that is parent
    var _Parent = parent;
    // apply that instead of just using the command parent itself
    _Parent.gotoAndStop(2);

  4. Alkan

    09.10.2008

    Reply

    Very Good Thanks.

  5. oli

    12.09.2009

    Reply

    Genius. I have been struggling with this and it is the only work around that does the trick. Thanks

Leave a Reply









Latest Theme From WooThemes

Unsigned

By WooThemes

Unsigned is a hugely powerful, cleverly developed, yet super easy theme to use for musicians and bands looking to showcase their music, tours, photos, videos and band members all from within WordPress. It even allows you to sell your albums and merchandise thanks to the WooCommerce integration. It truly is a massive theme that will cover your every need.

Theme Categories: Multimedia, Responsive

Latest Tweets