How can you determine if swf is played standalone

2019-03-01 02:40发布

问题:

I have two swf's. One "show" of some sort, and one "menu" that acts as a loader for "shows". The "show" swf can run in its own respect, or by being loaded via the "menu".

Is there a way to determine, if the "show" is run stand-alone or as loaded into the "menu"?

One solution is to have the "menu's" Loader object set a variable on the loaded "show", like myLoader.content.thisIsFromMenu = true; and then checking in the "show", if such a variable exists and is true. BUT I was wondering, if there is any more generic way, that would not require for the "show" to know anything about the "menu" to determine, if it is loaded into a swf or played by itself?

回答1:

if (root.parent && root.parent == stage) {
  // Standalone
}


回答2:

In the constructor of loaded swf:

if (stage && parent == stage) {/*I'm standalone*/}

Or maybe if (parent is Loader) will also work (vice versa logic)



回答3:

if (root.name == "root1") //standalone