A Flash Developer Resource Site

Results 1 to 7 of 7

Thread: why does everyone _root. everything?

  1. #1
    Senior Member
    Join Date
    Aug 2005
    Posts
    225

    why does everyone _root. everything?

    doesnt:

    stop();

    work just as well as:

    _root.stop();

    or does the _root. make it faster?

  2. #2
    Senior Member UnknownGuy's Avatar
    Join Date
    Jul 2003
    Location
    Canada
    Posts
    1,361
    It depends where the code is run, if you are in a method of a class, stop() controls the instance that is calling the method, _root would be needed to control the main timeline. You'll notice though that a lot of people don't like using _root, because _root can change if you import the game .swf into a container .swf, the _root becomes the containers .swf.

    There is a way around it, which I hadn't heard about until awhile ago which is _lockroot.

    For anyone interested here is a link to an article about it. It is pretty nifty.

    http://www.flashinsider.com/2005/08/...-_rooted-code/

    Hope that clears things up.

    Edit: Another way of thinking about it is stop() is the same as writing this.stop(), so if you are in the main timeline this=_root, so _root.stop()=stop(). When this changes from being called by a method or inside a clip, then you have to use _root, or a path to root like _r to access it.

  3. #3
    Senior Member
    Join Date
    Aug 2005
    Posts
    225
    thx for the info and i get it too

  4. #4
    Phantom Flasher... Markp.com's Avatar
    Join Date
    May 2000
    Posts
    16,034
    Yup, I try to avoid _root. _parent. works just as well, may be a little slower though

  5. #5
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Slightly off on a tangent but one thing which a lot of people miss and can lead to pulling your hair out errors is gotoAndStop/Play.

    If your using that on a mc ( ie, within your enterFrame / load code ) always put this. infront of it ( If you want to alter the frame of the mc itself that is ).

    It stops the local / global method conflict.

    Squize.

  6. #6
    Senior Member Gloo pot's Avatar
    Join Date
    Aug 2005
    Location
    Australia Mate!
    Posts
    874
    Huh?

    I just figured anything with _root. befor it affects to stuff on the main timeline and without it it affect the MC wich the code is in??

    EG : _root.gotoAndPlay(2); play frame 2 in your main timline and
    gotoAndPlay(4); playes frame 4 in your MC

    Am i mistaken?
    92.7 Fresh FM for all your South Aussies - Doof Doof music FTW people!

  7. #7
    Hype over content... Squize's Avatar
    Join Date
    Apr 2001
    Location
    Lost forever in a happy crowd...
    Posts
    5,926
    Not really, but Flash being the little minx that it is can get mixed up sometimes, so just get in the habit of adding this. when doing it on a mc.

    Squize.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center