0

I have 2 swf-s, main.swf and another.swf.
main.swf will load another.swf at run-time.
Corresponding classes for them are Main and Another.
Both of them import a common class Constant.

The problem is:
If I make changes to class Constant, like define a new constant for class Another, then I surely wants to compile another.swf.
Then, I run main.swf and load another.swf, BUT the changes of Constant are not applied!

In the contrary, I have to re-compile main.swf to make the changes applied to another.swf.
It looks like since another.swf is loaded by main.swf, so the import also relies on main.swf.
When you run main.swf first, class Main import the Constant class first, so any upcoming import is hidden (or ignored?), is this true?

Is the import only executed once, and is executed by the first played .swf?

The .swf load is done by flash.display.Loader class.

Marson Mao
  • 2,935
  • 6
  • 30
  • 45

1 Answers1

1

When a class is loaded, its fully qualified domain name (pacakge name + class name) is added to a global registry of sorts. When main.swf loads the Constant class, the class is cached. This registry is generated at compile time so main.swf has the Contant class definition cached as it was when it was compiled.

In fact, if you change Constant, you can recompile main.swf only and see that modified definition is available in another.swf.

sberry
  • 128,281
  • 18
  • 138
  • 165
  • That's true!! I can only recompile main.swf to apply changes, this also bothers me. Do you have any official article (adobe's or anyone) that explains all these mechanism? I'd really love to read all the details, thanks!! – Marson Mao May 30 '13 at 06:06
  • Why this cache behavior bothers me is that, I actually have lots of .swf to be loaded. And if the class is cached, I have to recompile both main and other .swf even though I didnt make any changes to main. – Marson Mao May 30 '13 at 06:08
  • @MarsonMao Well, consider a global var class as a global include, which forces you to recompile all your projects that use it if you alter it. It's normal. – Vesper May 30 '13 at 06:35
  • Ah, that's right, sorry I didnt make it clear. I didnt make `Main` to `import` `Constant` until I notice this behavior. I put import in Main to avoid recompile of all swfs, but actually I am searching for a better approach, like an external library for `Constant`. And I am searching for the answer of this behavior. – Marson Mao May 30 '13 at 07:13
  • use a runtime shared library. It makes no sense to compile classes in 2 different files. Or create a lib project with the shared classes, and link the library as external for one of the swf files. I guess you need the classes only at compile time. – Larusso May 30 '13 at 08:23