Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex: Get self SWF file name?

Is there a way I can programmatically determine the filename of the .swf my class is running in?

Thanks!

like image 893
JD Isaacks Avatar asked Dec 22 '09 20:12

JD Isaacks


2 Answers

Stage has a loaderInfo property, which contains a url property that has the information you're looking for. You can get the stage property from any DisplayObject in Flex.

trace(stage.loaderInfo.url);

like image 60
RJ Regenold Avatar answered Nov 03 '22 01:11

RJ Regenold


Just a helpful note: If you load one SWF into another, the loaded (inner) SWF will return an erroneous result if you use loaderInfo.url to try to get the filename. For instance, something like:

Path/To/Outer.swf/[[DYNAMIC]]/1

Instead of:

Path/To/Inner.swf

Beware!

That said, here is the code I use to get the current SWF name:

function SWFName(symbol:DisplayObject):String
{
    var swfName:String;
    swfName = symbol.loaderInfo.url;
    swfName = swfName.slice(swfName.lastIndexOf("/") + 1); // Extract the filename from the url
    swfName = swfName.slice(0, -4); // Remove the ".swf" file extension
    swfName = new URLVariables("path=" + swfName).path; // this is a hack to decode URL-encoded values
    return swfName;
}
like image 3
ivanreese Avatar answered Nov 03 '22 00:11

ivanreese