6

I am creating a library in AS3. Inside the library I make use of a bunch of classes/packages that need not be exposed to the end user of my lib. I want to only expose one of these classes.

I guess my questions are:

1) How are libraries commonly distributed in AS3?

2) Is there a .jar equivalent in AS3 that developers can include, but will only have access/knowledge of the classes I've declared as public?

Thanks!

Andy Hin
  • 30,345
  • 42
  • 99
  • 142
  • @see: http://stackoverflow.com/questions/6041832/what-is-the-best-way-to-distribute-as3-classes-and-packages/6045196#6045196 – JonnyReeves Feb 04 '12 at 09:23

2 Answers2

5

AS3 libraries are called SWCs. Like JARs they are just ZIP archives with some metadata included. You can build libraries either using Flash Builder library projects or mxmlc compiler in Flex SDK which is described for example here.

Good practice is to distribute SWC or source code. With docs or readme file of course.

Valentin Simonov
  • 1,768
  • 10
  • 14
  • Is it possible to create a SWC file without using the Flex framework? I just want barebone AS3. – Andy Hin Feb 03 '12 at 23:32
  • it isn't, unless you have the Flash IDE. – Lucas Feb 04 '12 at 01:44
  • 4
    @AndyHin, you need the Flex compiler to build the SWC, but you don't have to include the Flex framework (it won't be if you made no reference to it in your code). – laurent Feb 04 '12 at 09:18
3

Is it possible to create a SWC file without using the Flex framework? I just want bare-bone AS3.

Yes we are not forced into using flex, in fact Adobe doesn't even support Flex as their product officially anymore as it is now an open-source apache project. http://blogs.apache.org/flex/

The compiler itself for flash is open-source and free to use, that is why there are many third party IDEs and development tools that can also produce SWC libraries. The compiler just requires a special xml file in a zip in order to make a swc. So if you want to avoid doing this manually to the spec its just a matter of choosing a gui way to do this.

One of the most popular one open-source gui ways atm I believe is Flash Develop http://www.flashdevelop.org/ which has a plugin to do what you want. http://www.flashdevelop.org/community/viewtopic.php?f=4&t=2987 This IDE is highly recommended but if you need something more cross platform, I recommend Intellij Idea which is a great as3 and java ide, since you know what jar files are.

"only have access/knowledge of the classes I've declared as public?"

The classes in your swc will be no different to being part of your main project so if you create a swc with public or private it will be public or private the same way. To be honest though most code shared by blogs and repositories in the community are just raw *.as files, swc is handy however for shared libraries in a team and can make this more organised.

imp
  • 1,110
  • 8
  • 13
  • 1
    of interest, a .swc file is just a zipped folder containing a .swf with the embedded .as code and an .xml file. you can rename mySwc.swc to mySwc.zip and then unzip it to reveal these contents. additionally, this is where you can access the .swf file to decompile using one of several free flash decompilers, so using .swc as a means to protect your code is easily circumvented. – Chunky Chunk Feb 04 '12 at 18:21
  • yes it was obviously not designed to "protect" your code. It seems protecting your as3 code in general can only be done by making it harder, not impossible for others to reuse. Look into tools that obfuscate and alter the swf of your compiled code. – imp Feb 04 '12 at 22:41