我有一个班级设置,它看起来像这样:
package scripts
{
import flash.display.MovieClip;
import flash.display.Stage;
public dynamic class Upload
{
public function Upload()
{
}
public function getPostURL():String
{
return "test";
}
}
}
我正在通过以下方式实例化该课程:
var upload = new Upload();
var url:String = upload.getPostURL();
这很好用,我能够获取字符串,但是如何修改类才能返回FlashVars?我一直在寻找几个小时,但一直没能找到答案。
我正在使用此设置FlashVars:
<param name=FlashVars value="var=test" />
答案 0 :(得分:1)
对于添加到舞台的任何实例,您可以使用以下代码:
root.loaderInfo.parameters.var
<强>更新强>
package scripts
{
import flash.display.Shape;
import flash.events.Event;
// If you want to use an Uplaod class like a container,
// then you should extend it from Sprite.
public dynamic class Upload extends Shape
{
protected var _url:String = "";
public function Upload()
{
super();
addEventListener(Event.ADDED_TO_STAGE, addedToStageHandler);
}
protected function addedToStageHandler(event:Event):void
{
_url = root.loaderInfo.parameters.var;
}
public function getPostURL():String
{
return _url;
}
}
}
在Main.as
:
var upload = new Upload();
addChild(upload);
var url:String = upload.getPostURL();
或者没有Upload
类的其他变体。在Main.as
:
var url:String = loaderInfo.parameters.var;
答案 1 :(得分:1)