开发者

Loading external swf uses old code?

I'm having an issue running a swf within another. It seems to be running an incorrect version of the code. Here is an explanation of the environment.

a.swf (Document class: ClassA()) loads in b.swf (Document class: ClassB()) via typical loading methods:

var _loader:Loader = new Loader();

addChild(_loader);

//add relevant event listeners...

_loader.load(new URLRequest("b.swf"))

Right now, the constructor of ClassB is as such:

public function ClassB()

{

trace("ClassB() version 1.0");

}

If I publish both a.swf and b.swf, load b.swf into a.swf, I get the trace "ClassB() version 1.0"

Now, if I update ClassB() to trace("ClassB() version 1.1") and only publish b.swf, then run a.swf, I would expect that the output would be "ClassB() version 1.1," however, it is still "ClassB() version 1.0"!

I am not sure what is happening.

a.swf is definitely loading the new version of b.swf (I changed the objects on the stage in b.swf, which is added as a child of开发者_StackOverflow ClassA(), so those changes show)...but it is still running the old (1.0) version of ClassB's code. I also verified this by running b.swf on its own, and it shows 1.1

I can get it to run the 1.1 version of ClassB if I also republish a.swf

The first thing I can think of is that ClassA and ClassB share the same class path, so when I publish a.swf, it contains the version of ClassB that was created at that time (1.0) and then runs that version (instead of the new/1.1 version inside b.swf). Is that correct? Is there a way to avoid this while keeping them on the same class path? Or is something else the issue?

Thanks in advance!


This is possible if A.swf has a copy of ClassB compiled into it. By default, B.swf will be loaded into a child of A's ApplicationDomain. This means that if there are conflicting class definition (in this case, ClassB), then the parent's definition will be used. If the old ClassB version was also compiled into A.swf, then that version of the class will be used. This could happen easily if the files share the same class path.

As goliatone points out, check to see if you have any references to ClassB inside A.swf--for example, var foo:ClassB. This would cause ClassB to be compiled into A.swf. You can also verify this in the Flash IDE by checking "Generate size report" in Publish Properties->Flash.

You probably don't want to compile ClassB into A, anyway, if you are trying to load ClassB in dynamically as a module. To not compile ClassB in A.swf, you can explicitly tell the compiler not to include ClassB in A.swf. You can do this by adding -externs ClassB to the mxmlc command line. Flash Builder, FlashDevelop, etc. have this option in the project properties.

Alternatively, you could remove all references to ClassB in A.swf. If you have to instantiate it, do so indirectly: new (_loader.contentLoaderInfo.applicationDomain.getDefinition("ClassB") as Class)

You could also load B.swf into its own, separate ApplicationDomain: _loader.load(url, new LoaderContext(false, new ApplicationDomain()); This will cause the conflicting definitions to exist separately in their own domains.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜