Actionscript:
-
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
havent tested this, but wouldn’t this kind of work the same?
if(parent){
//container
}else{
//no container
}
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…
I use if(stage) in the Documents class´ constructor.
Funny, I use if(parent is Stage)
I used to use if(stage) till I found a few glitches (in IE I think).
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