2

I'm trying to recreate a modernized version of this tutorial here - but I'm having problems building and referencing a SWC file for inclusion in my Flash Builder project. Whenever I try to reference the SWC, Flash says it's "not a compile time constant" - can anyone help me with the process of building a SWC (mainly, naming it so that Flash Builder can reference it) - and then, in Flash Builder, creating that reference to the SWC? Thanks

Anil
  • 2,539
  • 6
  • 33
  • 42
mheavers
  • 29,530
  • 58
  • 194
  • 315

5 Answers5

4

To add a swc to Flash Builder, follow these steps:

Adding a swc to Flash Builder

NateJC
  • 131
  • 3
3

You can build a swc from Flash Builder by creating a Library project as Emanuil also answered already. Normally, all classes that are in the source path of the library project will end up in the swc and those classes are then usable in another project that has the swc in its library path.

Another way of creating a swc is by using Flash, publishing not only to a swf but to a swc too (it's a checkbox in publish settings). Then all library items that have "Export for ActionScript" checked and a class name, will end up in the swc for use in another project.

You reference classes from the swc exactly the same as you would reference a class in your own source path:

// this should be the package and class name of the class you need: 
//   not the name of the swc it comes from!
import some.package.name.ClassFromSWC; 

...

new ClassFromSWC();

Hope this helps...

frankhermes
  • 4,720
  • 1
  • 22
  • 39
  • Definitely helps. I'm doing all of this and I'm still not getting anything in my Flash Builder project though - I get no errors, but nothing shows up on stage. – mheavers Jun 13 '11 at 18:55
  • For something to show up on stage you need to add it to it: `addChild(something);`. This now goes a little beyond your original question... I think getting some other tutorial on how to create something in Flash would be a good idea here. – frankhermes Jun 13 '11 at 19:40
2

To build a SWC file you need to create a Library Project. You can find detailed instructions in the "About library projects" article in the Flash Builder documentation.

To use a SWC file in a Flex Project, just copy it into the libs folder of that project.

Emanuil Rusev
  • 34,563
  • 55
  • 137
  • 201
1

I don't know for Flash Builder, but in Flash Develop, you just have to right click on the swc file you want in the project files list panel, and click on "add to library".

2smacks
  • 168
  • 2
  • 9
  • Ok - I think I found that in Flash Builder - it's under properties > action script build path > add SWC - but how do you build an SWC that will have the name you give it - is that based on its document class? For example - if, in Flash Builder, I want to reference an SWC called "Vid" - do I just need to create a file called Vid.SWC, or does that SWC need to have a document class of "Vid" or what? – mheavers Jun 13 '11 at 17:10
  • But what do you do if you want to build, say, a movieclip or animation in Flash in the library, and use that in your .as file? – mheavers Jun 13 '11 at 17:33
  • simply : import MyClass.as myMc:MovieClip = new MyClass(params); – 2smacks Jun 13 '11 at 17:41
  • Thanks - I think I got the hang of it. I didn't realize you had to make a completely separate class file for a movie clip in your library. – mheavers Jun 13 '11 at 18:48
  • 1
    Just a note - this tutorial does a great job of walking you through this exact process: http://www.flashkit.com/tutorials/Getting_Started/How_to_I-James_Mc-1620/index.php – mheavers Jun 13 '11 at 19:18
  • Im following that tutorial exactly and ends up with: TypeError: Error #1007: Instantiation attempted on a non-constructor. Any ideas why? – David Lamm Feb 12 '17 at 22:49
0

Use Flex Library Project to create SWC like the comment above. There are many ways to include external code to your project.

_ Copy to libs folder since default build path included that folder.

_ Project Properties > Action script Build Path > Add SWC to add an SWC file which could locate anywhere in your file system.

_ Project Properties > Action script Build Path > Add Project to include your Flex Library Project, in case the project is under development, so that you don't need to export SWC file and copy it into your application project every time the library changes.

Harry Ninh
  • 16,288
  • 5
  • 60
  • 54