Is this swf in a container?

if(parent == stage){
   // no container
}else{
  // has container
}

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…

5 comments

  1. 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…

  2. 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 😀

Leave a Reply

Your email address will not be published. Required fields are marked *