希望这是一个很容易的问题:)
hoping this is an easy enough question :)
一些细节: 我使用Flash CS5,从来没有碰过的Flex。同样是做加载的SWF将是一个客户端 SWF,所以希望这可以与一个简单的几行的解决方案。
Some details: I am using Flash CS5, never touched Flex. Also the SWF that is doing the loading will be a client SWF, so hoping for a solution that could work with a simple couple of lines.
基本上里面我工作的SWF只包含一个简单的字符串:
Basically inside the SWF I am working on contains just a simple string:
var theString = "theString";
trace("theString = "+theString);
现在我一直在测试加载器SWF,将载入我的字符串SWF并获得最简单的方法变量。有什么想法吗?下面是我目前的破code:
Now I've been working on a test loader SWF that will load my String SWF and get the variable in the simplest way. Any thoughts? Below is my current broken code:
function loaderComplete(event:Event)
{
trace("... in loaderComplete");
getString = loader.content.toString();
trace("loader.content = "+loader.content);
trace("... getString = "+getString);
}
这是我的输出窗口:
theString = theString
... in loaderComplete
loader.content = [object MainTimeline]
... getString = [object MainTimeline]
我搜索的堆栈,发现类似的问题,但没有一个是正是我需要的:
I've searched on Stack and found similar questions, but none are exactly what I need:
跟踪的视频文件 - 嵌入FLV到SWF
^基本上我想要做的一样好,没有解答
^ Basically what I'm trying to do as well, no answers yet
to从一个SWF传递变量,以在AS3 另一个SWF
^听起来就像我的问题,但答案是Flex应用程序的例子
^ sounded just like my problem, but answer was a Flex application example
pass VAR值从一个SWF谁是firts人在里面装在AS3 另一个SWF
^这是接近,但我不知道如何实现所选择的答案,也似乎更多的是有点复杂的话,我需要
^ This was close, but am not sure how to implement the chosen answer, also seems a bit more intricate then I need
请帮忙!
让我们澄清一下: 1.装载器SWF,我们将调用父。 2.父加载的SWF中,我们将调用子。
Let's clarify a bit: 1. The loader swf, we will call the parent. 2. The swf loaded by the parent we will call the child.
孩子包含字符串,并且希望家长能够读取该字符串> 所以... 孩子必须定义字符串公共变量。 (这意味着你必须使用一个类文件吧,因为你不能在时间轴上声明属性public。)
The Child contains a string, and you want the parent to be able to read that string> So... The Child must define a public variable for the string. (This means you have to use a Class file for it, since you cannot declare a property public on the timeline.)
最后,家长将尝试并获得该属性。您可能需要包装在一个try / catch来处理情况,该字符串不会以present。
Finally, the parent will try and get that property. You may want to wrap that in a try/catch to handle cases where the string will not be present.
下面是一个例子子类。
Here is an example Child Class.
package
{
import flash.display.Sprite;
/**
* ...
* @author Zach Foley
*/
public class Child extends Sprite
{
public var value:String = "This is the child Value";
public function Child()
{
trace("Child Loaded");
}
}
}
这里是父类加载器:
package
{
import flash.display.Loader;
import flash.display.Sprite;
import flash.events.Event;
import flash.net.URLRequest;
/**
* ...
* @author Zach Foley
*/
public class Parent extends Sprite
{
private var loader:Loader;
public function Parent()
{
trace("PArent Init");
loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoaded);
loader.load(new URLRequest("child.swf"));
}
private function onLoaded(e:Event):void
{
trace("Child Loaded");
trace(loader.content['value']);
}
}
}
输出将是: 家长初始化 儿童加载 儿童加载 这是孩子的价值
The Output will be: PArent Init Child Loaded Child Loaded This is the child Value