Many times, we need to put the SWF into the page load, and the corresponding resources are placed on the page, loading the SWF in the Web page is usually through the "*.swf?p=. &p2=. "This way to call this SWF and arguments, if this page and SWF in the same directory (that is, the same folder) is not a problem, but for a project, we may have a lot of such pages, are placed in a folder difficult to manage, So we need to put them in different folders, such as using a.html to load b.swf,a.html in. /1/2, b.swf in. /3/4, then our SWF how to load the same directory with the SWF resources, we practice is: To obtain the SWF's absolute path, to obtain the SWF's absolute path, you can: var url:string = Stage.loaderInfo.url; We need to remove the file name Url.slice (0,url.lastindexof ("/") +1), on the Web page naturally work, according to the truth this machine can also work, but in fact: Display security sandbox error or load resource error, why?
On this machine, we run the SWF, get the value of the URL, the path is file:///C://upload/;
On this machine, we run the same directory under the HTML file, found the sandbox problem, loading problem, etc., the value of the URL is file://c:\upload\, so cannot find
So we need to change to: Url.slice (0,url.lastindexof ("\ \") +1); note: The preceding \ is just the escape character, which is actually the end of the last "\" When the path is encountered, so that the machine runs without problems.
Here's an example:
varurl:string=""; This. Loaderinfo.addeventlistener (Event.complete,onloadercomplete);//called when the SWF itself has finished loadingfunctionOnloadercomplete (e:event):void{ This. Loaderinfo.removeeventlistener (Event.complete,onloadercomplete); URL= Stage.loaderInfo.url;//get the absolute path to the main SWF as the path to the URLRequesturl = Url.slice (0,url.lastindexof ("/") +1);//Remove the file nameurl = url.slice (0, Url.lastindexof ("\\") + 1);//the preceding \ is just the escape character, which is actually the deadline for the path to encounter the last "\", in order to be able to run on this machine. //Supplementary Note: The following code is received from the HTML passed parameters, HTML parameters generally have two ways, the SWF can be used in the following way to obtain these parameters, to know, read on: for(varKey:stringinchparamobj) {Trace (Paramobj[key]); } Trace ((E.target as Loaderinfo). parameters["url"],"htm parameter url"); Trace ((E.target as Loaderinfo). parameters["CALLBACKFN"],"htm parameter Callbackfn"); Trace ((E.target as Loaderinfo). parameters["CF"],"htm parameter CF");}
There are two general ways to pass a parameter from HTML:
One:
<name= "movie" value= "/swf/upload.swf?url=http://localhost : 15100/handler.ashx&callbackfn=fasdfdasf&cf=upfile.c "/>
Two:
<name= "movie" value= "/swf/upload.swf"/> <name= "Flashvars" value= "Url=http://localhost:15100/ handler.ashx&callbackfn=fasdfdasf&cf=upfile.c "/>
[Actionscripte 3.0] SWF and Web communication