9Feb/100
Finding the base URL of your Flash
One of the most useful 'basic' tools of a Flash developer is to be able to find the URL of your Flash application, and it is very simple:
//in timeline trace(loaderInfo.url); //this returns the path of the Flash application stop();
The reason it is useful is because you can make your application behave differently depending on which environment it is in.
Your application may be expecting a flashvar which is only available if the Flash was embedded in an HTML. In order to test your functionality within the Flash IDE instead of creating two separate projects, you create some logic based on the URL of the movie:
//in timeline import flash.display.LoaderInfo; var myVar:String; <pre>var paramObj:Object;</pre> if(loaderInfo.url.indexOf('file://')==0){ //if the URL begins with 'file://' it means we're working locally //locally, flashvar is not going to be available //we'll give it a default value myVar = 'foo'; }else{ //we assume that not working locally means we're working live //get flashvar from HTML paramObj = LoaderInfo(root.loaderInfo).parameters; //set myVar to equal myLiveVar from the flashvar myVar = paramObj.myLiveVar; } stop();