Say you have a Flash widget that you need to put on the server to receive dynamic data yet you want to test it in Flash with all of your nice trace(); statements etc… The only trouble is that when you post it to the server you always forget to comment out the values that you test with. These are the hard coded values you typed into the file or Class. You don’t want to have to remember each time you FTP the file up to the server to comment out those pesky variables that are critical for testing in the Flash authoring tool.
The solution to the problem is quite simple. All you need to do is ask Flash where it lives. You do this by having Flash ask what is its URL using this._url
Here is the code:
if (this._url.substr(0,5) == "file:") { var fillBytes:Number=978; var totalBytes:Number=2712; }
Here is the explanation:
- Setup a conditional statement - if()
- Because anything run in Flash will be located at a file path, ask if the location(_url) name starts with the characters "file:" - this._url.substr(0,5) == "file:"
- If the answer is yes then set your variables - var totalBytes:Number = 2712
A web address will never start with the characters "file:" but rather "http" or the name of a subdomain. Because of this the variables will not yet be defined when the file is on the server and your .swf will be ready to receive anything the server has to throw at it. And yet, you will always be able to test it in the Flash authoring environment.
Happy Flashing