今天我试图获取我的 Flash 电影所在的 URL。
I found 这里有一个类似的问题 https://stackoverflow.com/questions/396412/how-can-my-flash-app-determine-its-own-url,答案是链接到 Flash 的 LoaderInfo http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/display/LoaderInfo.html#includeExamplesSummary方法,但我不确定我是否正确使用它作为我的测试电影中的文本字段:http://leongaban.com/stackoverflow/getUrl/ http://leongaban.com/stackoverflow/getUrl/不显示网址
更新!工作代码
我所需要的只是这个:stage.loaderInfo.url
:)
package {
import flash.display.Stage;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.events.Event;
import flash.text.TextField;
import flash.text.TextFieldAutoSize;
import FontsTest;
public class LoaderInfoExample extends Sprite
{
private var myTextField :TextField = new TextField();
private var urlIs:String = "";
public function LoaderInfoExample() {
urlIs = stage.loaderInfo.url;
trace(stage.loaderInfo.url);
addEventListener(Event.ADDED_TO_STAGE, initHandler);
}
private function initHandler(event:Event):void {
myTextField.defaultTextFormat = FontsTest.Arial14Bold;
myTextField.border = true;
myTextField.antiAliasType = flash.text.AntiAliasType.ADVANCED;
myTextField.selectable = true;
myTextField.mouseEnabled = true;
myTextField.autoSize = TextFieldAutoSize.LEFT;
myTextField.text = "Url is = "+urlIs;
addChild(myTextField);
}
}
}
http://leongaban.com/stackoverflow/getUrl/ http://leongaban.com/stackoverflow/getUrl/
如果我的理解是正确的,那么你的做法就有点错误了。您不需要创建新的加载程序 - .swf 在舞台上保存对其自己的 loaderInfo 对象的引用。
因此,如果您想追踪 .swf 文件的当前位置,请执行以下操作:
trace(stage.loaderInfo.url);
这有帮助吗?
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)