如何将FlashVars与ActionScript 3.0结合使用?
时间:2020-03-06 14:29:26 来源:igfitidea点击:
我找到了使用Flash参数的指南,认为可能在此处发布很有用,因为Flash CS3缺少读取这些参数的用法示例。
查看链接的答案
解决方案
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
整篇文章位于:
http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html
重要的提示!这仅在主类中起作用。如果我们尝试将参数加载到子类中,那么我们将一无所获。
不知道为什么他的示例调用LoaderInfo。 DisplayObject类具有其自己的(只读)loaderinfo属性。只要主类扩展了DisplayObject,就可以直接调用该属性
package { import flash.display.Sprite; public class Main extends Sprite { public function Main() { var test1:String = ''; if (this.loaderInfo.parameters.test1 !== undefined) { test1 = this.loaderInfo.parameters.test1; } } } }
从文档中:
Returns a LoaderInfo object containing information about loading the file to which this display object belongs. The loaderInfo property is defined only for the root display object of a SWF file or for a loaded Bitmap (not for a Bitmap that is drawn with ActionScript). To find the loaderInfo object associated with the SWF file that contains a display object named myDisplayObject, use myDisplayObject.root.loaderInfo.