[英]flash & Actionscript3 - passing objects to external swf
Firstly Id like to say thanks to everyone who has helped me this week with some flash problems Iv had. 首先,我要感谢本周为Iv遇到的一些闪光灯问题提供帮助的每个人。 Its been a great help.
这是一个很大的帮助。
Now to what I hope if my final problem 现在我希望我的最后一个问题
I have a object, called friends, It contains the url to facebook profile picture, ie 我有一个称为朋友的对象,它包含Facebook个人资料图片的网址,即
friends.friend1 = "http:// etc";
I have a swf file called, master.swf, which is passed the information to create the object through flashvars. 我有一个名为master.swf的swf文件,该文件会通过flashvars传递信息以创建对象。
I need to get the object OR the flashvars info to the externally loaded swf, called pageOne.swf. 我需要将对象或flashvars信息获取到外部加载的swf,称为pageOne.swf。
I have seen and tried several different methods, but now seem to give me what I need. 我已经看到并尝试了几种不同的方法,但是现在看来可以满足我的需求。
The important thing is that the pageOne.swf has access to the flashvars/object BEFORE it is rendered to the screen, as the info in the object/flashvars are used to construct it. 重要的是,pageOne.swf在呈现到屏幕之前可以访问flashvars / object,因为object / flashvars中的信息用于构造它。
I am using the loader class to load the swf, castin it as a movieClip 我正在使用loader类加载swf,将其投射为movieClip
Anyone have any ideas how to to the above? 任何人都对上面有什么想法吗?
CODE EXAMPLES: 代码示例:
master.swf master.swf
var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters;
I need to either pass this to the pageOne.swf, OR make it available to it 我需要将其传递给pageOne.swf,或使其可用
How Im loading the external swf 我如何加载外部瑞士法郎
function getFirstLevel()
{
my_Loader = new Loader();
my_Loader.contentLoaderInfo.addEventListener(Event.COMPLETE, finishLoading2);
my_Loader.load(new URLRequest("pageOne.swf"));
function finishLoading2(loadEvent:Event) {
my_loadedSwf = loadEvent.currentTarget.content as MovieClip;
addChild(my_loadedSwf);
stage.addEventListener(Event.ENTER_FRAME, my_loadedSwf.enterFrameHandler);
stage.addEventListener(KeyboardEvent.KEY_DOWN, my_loadedSwf.myOnPress);
stage.addEventListener(KeyboardEvent.KEY_UP, my_loadedSwf.myOnRelease);
stage.focus = my_loadedSwf;
}
}
Thanks 谢谢
Either append it to the url and then access it through LoaderInfo.parameters, or have both swf's share access to the same class definition and store it there. 要么将其附加到url,然后通过LoaderInfo.parameters访问它,要么让两个swf共享访问相同的类定义并将其存储在那里。
The first example: 第一个例子:
my_Loader.load(new URLRequest("pageOne.swf?friend1=..."));
Then, inside of pageOne.swf access it through loaderInfo.parameters: 然后,在pageOne.swf内部通过loaderInfo.parameters访问它:
this.loaderInfo.parameters.friend1
For the second case (and I actually prefer this one), in main.swf: 对于第二种情况(我实际上更喜欢这种情况),在main.swf中:
import shared.Model; // have a class which has a public static facebook url
// property, or have it be a Singleton with that property
// Obviously, the class name is only an example.
/* ... */
shared.Model.facebookURL = "..."
Then, in the loaded swf: 然后,在加载的swf中:
import shared.Model;
/* ... */
var url:String = shared.Model.facebookURL
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.