in AS3 how to use this.parent != null to detect stand alone run of a swf or if in a parent swf
I have a 'shell' swf that i use to navigate a series of swfs. When i want to test or run a swf standalone i want to detect that no parent is present and locate XMLS or images in a local path. If i run in the parent SWF i understand that paths are realative.
The code below doesent work because this.parent evaluates to [object Stage]
if (this.parent != null) {
xmlURL = "TheProtocol/" + sevencharid + "/xml/clientconversation.xml";
trace("in top");
} else {
xmlURL = "xml/clientconversation.xml";
trace("in开发者_JS百科 bot");
}
You can check if the parent is the stage then:
if(this.parent is Stage) {
trace("standalone swf");
} else {
trace("not standalone swf");
}
This should work if that code is executed from the root.
An alternative that would work not only from the root would be:
if(this.root.parent is Stage) {
trace("standalone swf");
} else {
trace("not standalone swf");
}
This will work as long as the object is added to the display list (otherwise this.root will be null).
If you want to account for that, then you could do:
if(this.root) {
if(this.root.parent is Stage) {
trace("standalone swd");
} else {
trace("not standalone swf");
}
}
精彩评论