Didn’t get any real resolution to my last post. But kind of worked out what is going on. When you have an symbol in the library exported first frame, apparently those classes are also exported for the compiler.
Apparently when you reference a class, the compiler first looks in the class path for that class, and if found, it will use that class for type checking. Failing to find the class in the class path, it will check any classes that are exported first frame from the library, and if found, will use that.
You can prove this by doing the following:
1. Make a class:
class Test extends MovieClip { public var something:String; public function Test(){ } }
2. Make a component based on this class and export the swc.
3. Close the original file, refresh your components panel and add the new component to a fresh new fla.
4. Add the following code to that fla:
var x:Test = attachMovie("Test", "x", 0); x.something = 5;
That will generate an error, because “something” is defined as a string, and you are feeding it a number.
5. Now, change the class file (make sure it is still in the class path of the new movie):
class Test extends MovieClip { public var something:Number; public function Test(){ } }
6. No more error. Notice the code inside the component didn’t change.Only the class file. So Flash is checking the class path before the internal component. Now, delete the class file, or move it out of the class path, or rename it, so that the compiler can’t read it. Again, you get the error. Failing to find the external class file in the class path, the compiler uses the class definition inside the component.
7. So far, so good. But now, uncheck first frame export on the component in the new movie. Now, obviously this is going to fail in two ways. First, since the component does not appear on stage and is not first frame, it won’t be included in the swf, so won’t attach. And obviously since it’s not included in the swf, its class file won’t be included, so you’re going to get an error saying that the class could not be loaded. (Assuming that your original class .as file is still not accessible.)
8. Now, put an instance of the component on Stage. This forces it to be included in the swf. However, you’re still going to get a compile time error of being unable to load the class. Apparently if not exported first frame, the internal classes are available at run time only, not compile time. Unfortunately, this error will cause the whole statement to fail and the component will not even be attached.
9. I’m not sure if there is some way to force the classes to be available at compile time. The only solution seems to be to bundle intrinsic classes with your swcs. These should be placed in the class path so the compiler can use them for type checking at compile time. The odd thing though is that the intrinsic classes are already created and included in the swc for that very purpose, and they do work if first frame is selected. It’s a shame they don’t work in other cases. But, barring any further developments, that’s the solution I see.
Don’t want to add to the frustration, but there’s something interesting with some MM classes.
If you open up the “Classes.fla” common library, and dump the UtilsClasses.swc on stage the following code will work:
var strClass:Function = mx.utils.ClassFinder.findClass(“String”);
var str = strClass(“some string”);
trace(str);
What’s interesting is, if you uncheck the “export in first frame” for the Utils library symbol, it STILL works (as long as it’s in the library). Is this what you are trying to do, if so how is MM doing it? They seem to be able to activate intrinsic classes merely by the presence of the SWC in the lib.
Unzipping DataBindingClasses.swc (which unlocks XPathAPI) I can’t see any differences to a regular swc. Hopefully there’s something you can do to solve this.
Rich
You can use the somewhat hard to find exclude file method.
If some.fla has a file in the same directory named : some_exclude.xml the xml file can specify all class code to exclude from the published swf, the class code is used only for typechecking at compile time. Especially useful if you publish a whole bunch of swfs that all use the same class code, because flash only loads a class once, so it wastes bandwidth to include it in every file.
exclude file contents read as follows :
with an asset for every class you wish to exclude, and it is important to note that flash will NOT exclude class B if class A uses class B even when class A is excluded, so you must specify them all, and there are no wildcard methods to exclude a whole package.
I usually just maintain one exclude file that excludes all my components, and simply rename a copy for each child fla. I have thought of writing a jsfl command to write the exclude file -> publish -> then delete the exclude file, for a whole project at once ( nice to have ), but haven’t gotten around to it yet…
Cheers, Jesse
Evidently I was censored in my last post:
here is the exclude file contents with a little character replacement
(excludeAssets )
(asset name= “mx.controls.List ” ) (/asset )
(/excludeAssets )
Cheers