Is this swf in a container?

Actionscript:
  1. if(parent == stage){
  2.    // no container
  3. }else{
  4.   // has container
  5. }

Found myself writing this snippet today.... it figures out if the current swf is inside a container (Loader) or not... lots of other ways to do this... feel free to post your version in the comments...

This entry was posted in Loader, external data, misc and tagged , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

5 Comments

  1. Posted October 8, 2009 at 1:01 pm | Permalink

    havent tested this, but wouldn’t this kind of work the same?

    if(parent){
    //container
    }else{
    //no container
    }

  2. Posted October 8, 2009 at 1:11 pm | Permalink

    no… because the parent is either the stage or a loader… the parent is the stage if the swf isn’t in a container and the parent is a loader if it is in a container…

  3. Posted October 8, 2009 at 1:21 pm | Permalink

    I use if(stage) in the Documents class´ constructor.

  4. Cay
    Posted October 8, 2009 at 3:16 pm | Permalink

    Funny, I use if(parent is Stage) :)
    I used to use if(stage) till I found a few glitches (in IE I think).

  5. Posted October 8, 2009 at 5:28 pm | Permalink

    This snippet is very useful for when you are creating a web site’s sections as external swfs that are loaded. There is probably an initialize method that is triggered by the main app when it feels like it, but while testing you’d like to have that method trigger automatically.
    What is pain and I still haven’t found a solution for is when these external swfs load assets themselves such as images. Since when their loaded by the main swf they are taken to its level, relative paths within them stop working, so you have to edit part of the path depending on wether you will use the swf as standalone, or in the main app.
    If you have any snippet/suggestions for that, it would be a blessing :D

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*