SWC with embedded assets... having a very BAD time!

Hi All!

I have tried it at other forums but had no luck, and a big research on Google was equally unuseful.

I am very puzzled…

I used to be able to create distributable components in AS2 (swc files) containing class code and assets (movieclips). And it used to be really easy.

Now I am struggling with Flash CS4 and AS3 and all my attempts were frustrating, as no matter what I try it simply doesn’t work. I am starting to assume that maybe it is not possible anymore to do in AS3? Maybe this kind of thing is deprecated in Flash now???

Let’s see what I have tried:

  1. I started with a new FLA and named it ‘MyComponent.FLA’. Then I drawed a green square, converted it to a mc and named it as ‘MySquare’. Then I tagged ‘Export for ActionScript’ and ‘Export in Frame 1’. Then I named the class as ‘MySquare’ and set the base class to ‘flash.display.MovieClip’. This is my asset (a green square movieclip).

  2. Created an empty movieclip and dragged the asset within it. Then I named it as ‘MyComponent’. Then I tagged ‘Export for ActionScript’ and ‘Export in Frame 1’. Then I named the class as ‘MyComponent’ and set the base class to ‘flash.display.MovieClip’.

  3. Right-clicked it in the library and chose ‘Component Definition’. Then in class field I typed ‘MyComponent’ and tagged ‘Display in Components Panel’.

  4. Crated a new AS file, called it ‘MyComponent.AS’ and typed the following code:


package { 

    import flash.display.MovieClip;
    public class MyComponent extends MovieClip
    { 

        private var _square:MovieClip; 

        public function MyComponent()
        {
            _square = new MySquare();
            addChild(_square);
        } 
    }
}

  1. Back to ‘MyComponent.FLA’, right-clicked the ‘MyComponent’ object in the library and chose ‘Export SWC file’. That was ok, no warnings, no errors. Then I just copied this new SWC to my components folder.

  2. Created a new FLA and named it ‘test.FLA’.

  3. Reloaded the components panel, and my new component showed up. Then I dragged it into library.

  4. Then I type the following code:


    var test:MyComponent = new MyComponent();
    trace (test.visible)

  1. I ran the new app and it was ok, no errors and no warnings. The trace statement spit out ‘true’ what means that the new class is really there, but… I cannot see the green square. But when I click onto the ‘MyComponent’ in the library, the preview shows up the green square, what means that it IS THERE in the component. So, why it doesn’t show up in the stage after the class be intantiated?

What I am doing wrong? Or this kind of thing is not possible to be done with AS3?