swf現在のページのパスを取得する
2552 ワード
現在のプロジェクトでコンパイルされているSWFが存在するサーバパスまたはローカルパスをASプロジェクトで取得package {
import flash.display.Sprite;
public class HelloWorld extends Sprite
{
public static var currSwfUrl:String;
public function HelloWorld(){
// ,
var doMain:String = this.stage.loaderInfo.url;
var doMainArray:Array = doMain.split("/");
if (doMainArray[0] == "file:") {
// “/” “\” ,
if(doMainArray.length<=3){
currSwfUrl = doMainArray[2];
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf(currSwfUrl.charAt(2)));
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
currSwfUrl = currSwfUrl + "/";
trace(" : "+ HelloWorld.currSwfUrl);
}
}
}
Flex Webプロジェクトで現在のプロジェクトでコンパイルされているSWFが存在するサーバパスまたはローカルパスを取得
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="initApp()">
<mx:Script>
<![CDATA[
public static var currSwfUrl:String;
private function initApp():void{
// ,
var doMain:String = this.parent.stage.loaderInfo.url;// AS
var doMainArray:Array = doMain.split("/");
if (doMainArray[0] == "file:") {
if(doMainArray.length<=3){
// “/” “\” ,
currSwfUrl = doMainArray[2];
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf(currSwfUrl.charAt(2)));
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
currSwfUrl += "/";
trace(" : "+ HelloFlex.currSwfUrl);
}
]]>
</mx:Script>
</mx:Application>
JS現在のページのパスと名前を取得するには:
//現在のページ名(接尾辞なし)function pageName(){var a=location.href;var b=a.split("/");var c=b.slice(b.length-1,b.length).toString(String).split("."); return c.slice(0, 1);}//現在のページ名(接尾辞付き)function pageName(){var strUrl=location.href;var arrUrl=strUrl.split("/");var strPage=arrUrl[arrUrl.length-1];return strPage; }
package {
import flash.display.Sprite;
public class HelloWorld extends Sprite
{
public static var currSwfUrl:String;
public function HelloWorld(){
// ,
var doMain:String = this.stage.loaderInfo.url;
var doMainArray:Array = doMain.split("/");
if (doMainArray[0] == "file:") {
// “/” “\” ,
if(doMainArray.length<=3){
currSwfUrl = doMainArray[2];
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf(currSwfUrl.charAt(2)));
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
currSwfUrl = currSwfUrl + "/";
trace(" : "+ HelloWorld.currSwfUrl);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" initialize="initApp()">
<mx:Script>
<![CDATA[
public static var currSwfUrl:String;
private function initApp():void{
// ,
var doMain:String = this.parent.stage.loaderInfo.url;// AS
var doMainArray:Array = doMain.split("/");
if (doMainArray[0] == "file:") {
if(doMainArray.length<=3){
// “/” “\” ,
currSwfUrl = doMainArray[2];
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf(currSwfUrl.charAt(2)));
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
}else{
currSwfUrl = doMain;
currSwfUrl = currSwfUrl.substring(0,currSwfUrl.lastIndexOf("/"));
}
currSwfUrl += "/";
trace(" : "+ HelloFlex.currSwfUrl);
}
]]>
</mx:Script>
</mx:Application>