在 swf 之间共享代码

发布于 2024-08-05 22:13:49 字数 531 浏览 8 评论 0原文

假设我有两个 swf A 和 B,在运行时,swf A 加载 swf B,并且我希望在它们之间共享代码,以最大限度地减少文件大小和下载时间。

如果 swf B 有一些代码(例如 com.blah.HelloWorld),我告诉编译器将 swf B 的源代码放在 swf A 的类路径中,但只进行编译时链接,而不实际将 com.blah.HelloWorld 编译到 swf A 中 这是

有效的,我已经尝试过使用 -includes 和 -externs 编译器选项。

然而,我的问题是我希望以另一种方式做到这一点。即 swf A 和 B(以及可能的 swf C)都需要 com.blah.HelloWorld,但我希望将 com.blah.HelloWorld 编译为 swf A,将其作为 swf B(以及可能的 C)中的外部引用.)

我尝试使用 externs 和 include 来执行此操作,但是当我执行此操作时,我收到了 ReferenceErrors。

我想在没有单独的 rsl 的情况下执行此操作,这样我就可以减少 http 请求的数量。 这可能吗?

Lets say I have two swfs A and B, and at runtime, swf A loads swf B, and I wish to share code between them, to minimize file size and download times.

If swf B has some code (say. com.blah.HelloWorld), I tell the compiler to have swf B's source in swf A's classpath, but only do a compile-time link and not actually compile com.blah.HelloWorld into swf A.

This works, and I have tried it, using a the -includes and -externs compiler options.

However, My problem is that I wish to do this the other way. i.e. swf A and B (and potentially swf C) all need com.blah.HelloWorld, but I want com.blah.HelloWorld to be compiled into just swf A, have it as an external reference in swf B ( and potentially C as well.)

I tried doing this using the externs and includes, but I get ReferenceErrors when I do this.

I want to do this without a having a separate rsl, so I can reduce the number of http requests.
Is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

尐偏执 2024-08-12 22:13:49

您可以将 Flex 应用程序拆分为模块

或者,您可以使用 ApplicationDomain 类的 getDefinition 方法从运行时加载的 SWF 访问各个类:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
loader.load(new URLRequest("c.swf"));
//..
private function onLoad(e:Event):void
{
  var domain:ApplicationDomain = LoaderInfo(e.target).applicationDomain;
  var Type:Class = domain.getDefinition("pack.MyComponent") as Class;
  var myBox:Sprite = new Type();
  addChild(myBox);
}

You can split your flex application into modules.

Or you can access individual classes from an SWF loaded at runtime using the getDefinition method of the ApplicationDomain class:

var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.COMPLETE, onLoad);
loader.load(new URLRequest("c.swf"));
//..
private function onLoad(e:Event):void
{
  var domain:ApplicationDomain = LoaderInfo(e.target).applicationDomain;
  var Type:Class = domain.getDefinition("pack.MyComponent") as Class;
  var myBox:Sprite = new Type();
  addChild(myBox);
}
迷鸟归林 2024-08-12 22:13:49

我不确定我是否完全理解你的问题,但我认为你可以使用 AS3 Loader 类来做你想做的事。格式将是这样的 - 假设我们正在创建您的主应用程序(称为“a.swf”),并且您想要访问已编译到另一个应用程序(称为“b.swf”)中的方法和属性),你会这样做:

var SWFB:Object; // empty at first as a placeholder.

var url:URLRequest  = new URLRequest("b.swf");
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
l.load(url);

function loaded(e:Event):void {
 SWFB = e.currentTarget.content as Object;
 initApp();
}

function initApp():void {
 SWFB.someMethodCall();
}

......我认为这会起作用。我现在无法测试它,但尝试一下并告诉我。基本上,您将加载 b.swf 作为基本对象,然后您可以针对该对象调用方法。

请告诉我这是否有效,如果无效,我明天可以为您改进。

I'm not sure I'm quite understanding your question, but I think you can use the AS3 Loader class to do what you want. The format would be something like this - let's say we're creating your main app (which will be called "a.swf") and you want to access methods and properties that have been compiled into another app (called "b.swf"), you'd do this:

var SWFB:Object; // empty at first as a placeholder.

var url:URLRequest  = new URLRequest("b.swf");
var l:Loader = new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded);
l.load(url);

function loaded(e:Event):void {
 SWFB = e.currentTarget.content as Object;
 initApp();
}

function initApp():void {
 SWFB.someMethodCall();
}

... and I THINK that'll work. I can't test it right now, but try it and let me know. Basically you're going to be loading b.swf in as a basic object, and you can then call methods against that object.

Please let me know if that worked, and if not I can refine it for you tomorrow.

嘿咻 2024-08-12 22:13:49

我不确定这是否正是您想要的,但您可以使用一些 javascript 来允许两个 swf 一起工作。

这是一个教程:

http://greeneggsandcam.com/tutorials/connect-2-swfs

I'm not sure if this is exactly what you want, but you could use some javascript to allow the two swfs to work together.

Here is a tutorial:

http://greeneggsandcam.com/tutorials/connect-2-swfs

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文