In Flash, if i create a custom M开发者_C百科ovieclip, and compile it to a SWC, i can use it in .fla files (by linking to the .swc)..
var mcInstance = new CustomMovieClip();
addChild(mcInstance);
All the arrangement of graphics on the custom movieClip's layers is preserved.
If i subclass UIComponent and compile to a swc, I can use the custom Class in my .fla file, but the new instance doesn't seem to construct the children arranged on the layers.
I know that the correct way to make a custom component is to have the two frames, first to specify bounding box, second frame for assets, and that the first graphic in frame 1 is removed at runtime. But i'm not really trying to make a reusable component - i just want to use the UIComponent class (It seems to have some nice extensions to Sprite).
As i really want some hand-positioned layers inside the component i figured i could have the bounding box as the first element on frame 1 (knowing that it would be removed), but any other items i put on frame 1 would be preserved - buttons, images, lines, etc.
Is this possible?
Isn't UIComponent for Flex? I don't think that will work inside a FLA.
So i figured it out.. I was somehow linking against the original .as file and not the symbol in the .swc.
Example: i have a symbol (instance of default MovieClip) in a .fla composition
I rename it thus…
Properties : Class : "CustomMovieClass"
NB: I haven't created the .as file yet. I get the little warning - "A definition for this class could not be found in the classpath, so one will be automatically generated in the SWF file upon export".
I export the movieclip as Assets.swc.
-- have a rest, then
Create new TestingAssets.fla file, add "Assets.swc" to the Library path. From some code in this project…
var ob1:CustomMovieClass = new CustomMovieClass();
addChild(ob1);
Yay! it springs to life, all the animations i did in the CustomMovieClass timeline are incorporated fine.
-- another rest, then
Back in the original project, create CustomMovieClass.as
package {
import flash.display.MovieClip;
public class CustomMovieClass extends MovieClip {
// Simplest custom class definition
}
}
and re-export Assets.swc
Back in TestingAssets.fla, build and run - Nothing (compiles and builds fine, but no animations).
So i put a typo in CustomMovieClass.as and build again, remember i'm linked against the .swc and i swear to you that this CustomMovieClass.as file isn't in the classpath or Library Path… and "Compiler Error". So somehow it is linking in the original src and not the compiled into swc version.
Thanks for listening.
精彩评论