as3 extract class reference from swc - apache-flex

Does anyone know how to extract a class reference from an SWC file? I know I can right click / "Go to definition", and view the class definition.
I need to extract these for each class in an SWC. Can anyone provide a method to do so automatically?
Best,
Frank

I'm not sure, what do you mean saying "extract".
If you need to use some class from SWC, just set this SWC as a library for your project in your IDE.
If you are talking about viewing source code, that's almost impossible, because SWC is an archive with compiled classes (swf). You may use flash decompilers to get some source code from it.
BTW, IntelliJ IDEA can parse swc and show you fields and methods' ptototypes.

If you're trying to extract classes from the Flex SDK itself, you can grab the entire project using SVN or browse their online class summary documentation.

A list of the classes packaged into the swc is available from the catalog.xml file in the swc.
Rename the .swc to a .zip file, and you can access it.
However, if you want the actual methods in each class, I'm afraid you're out of luck.

Related

drag and drop of swc components

We need a capability by which we can drag and drop swc components in our Flex Application.
Any ideas would help.
Thanks
SWC is ZIP archive. You can unpack it with any ZIP library, inside you'll find catalog.xml, where library classes are listed (script.#name), and library.swf. You can load it with Loader.loadBytes after extraction in your ApplicationDomain. Knowing class names, you can get classes with getDefinitionByName.
Just curious - what your application is going to do with unknown classes in runtime?

Flex Builder: Not picking up new files

I have a working AS3 project and it compiles fine to a SWF. I added a new file (via various means: import, drag-drop, new), but it doesn't compile this new file. I'm using Flex Builder 3. I've tried a clean an rebuild. I've tried renaming. It picks up the existing files fine, but not the new one. The project is set to use a HTML wrapper. I see some build files (I think). The new file is in an existing folder and package.
Any idea what could be wrong?
First, the SWF Compiler will optimize your end code. If you never use a class or create an instance of it anywhere in your application; that code will never be compiled in your application. this is a common occurrence if you're using Flex Remoting with some backend; and a VAlue Object is never instantiated directly, instead you're always returning arrays of it. You'll find you get a lot of "Generic Objects" without the backend object-to- AS3 object translation of the Flex Remoting Gateway.
You didn't specify what type of file you are adding. If it is an ActionScript file it won't automatically be compiled in the swf. You'll have to 'include' it in another class somehow. IF it is an ActionScript class or MXML Component, make sure you are using that class somehow in your code. If it is another file type, such as an image or other asset you'll have to embed that file into your code somehow.
We might be able to offer more help if you were to tell us what type of file is not being added to the final SWC. Also tell us how you can tell.

How can I access data from a .fla file using Actionscript 3, Flex 4 SDK, and FlashDevelop?

Someone sent me a .fla file containing several art assets, with instances all configured to be displayed properly and in the right positions. However, since I'm using FlashDevelop with the Flex 4 SDK, I have no idea how to access these instances in code. Some of the objects are MovieClips that I need to modify the size of, and others are Dynamic Text objects that I need to change the display strings of at runtime.
If you have access to Flash (as in the development tool) you can right-click on a MovieClip in the library and select "Export SWC file".
The SWC file will contain all of the elements that have the "Export for ActionScript" property enabled. Place this SWC file on your classpath and FlashDevelop will tell the Flex SDK to link against it when building your final SWF.
If you don't have access to Flash to export the SWC you will need to get the other person to export the SWC file for you - you can't link against the FLA directly.
There's no obvious solution to this. basically, you will have to traverse the display list to find them, using numChildren, getChildAt etc. if you're lucky, they are named and you can use getChildByName.
greetz
back2dos

Force compile-time linking of all classes in a SWC

Using Flash CS4, I am making a game that has a dozen or so sounds and a couple of music tracks. To cut down on publish/compile time, I have moved the sounds and music into an (external) SWC, which is located in a "Library Path" for the project. This works, but with a caveat...
Until before I externalised the assets, I had been dynamically instantiating the Sound objects of the embedded sound by getting their classes with getDefinitionByName.
// something like...
var soundSubClass:Class = Class(getDefinitionByName(soundClassName));
var mySound:Sound = new soundSubClass();
But now that they're located in an external SWC, I need to have "concrete" references to the classes in order to load them like this, otherwise they are not included in the published SWF, and there is a runtime error when getDefinitionByName tries to get a class that doesn't exist.
So, my question: in Flash Professional CS4, is there any way to force a library's assets to be included, regardless of whether they are statically linked?
FlashDevelop has a compiler option "SWC Include Libraries", which is exactly what I want, and is distinct from the "SWC Libraries" option. The description of the "SWC Include Libraries" option is "Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used."
(Also, it's important to me that all the assets are contained within the one compiled SWF. Linking at runtime isn't what I'm after.)
Unfortunately, I don't think so. I hope this is fixed in CS5, but I wouldn't bet on it...
The current (aggravating) standard is to have a manifest class in your SWC that references all the root classes in the rest of the library:
public class MyLibManifest {
public static function manifest():void {
var class1:Class = Class1;
var class2:Class = Class2;
// etc...
}
}
Then, somewhere in your main .fla...
import com.mylibrary.MyLibManifest;
...
var myLibrary:Class = MyLibManifest;
There's no way to pull in and embed every class in an SWC by default in Flash CS4/CS5, but you may be able to do this with:
FlashDevelop
As you already know, this program's project properties has compiler options that differentiate between:
SWC Libraries: "Links SWC files to the resultin gapplication SWF file. The compiler only links in those classes for the SWC file that are required."
SWC Include Libraries: "Links ALL classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used."
That second option "SWC Include Libraries" could be useful, because if you simply compile your FLA as-is into a SWC, then put that SWC and your other SWC into FlashDevelop as SWC Include Libraries, it should compile/merge them into a single SWF that will work like you want.
FlashDevelop could also simply help you build a hard-coded list of Classes in an SWC, because if you link in the SWC as a SWC Library, it will show up in the project explorer, and you can see a list of all the classes in the SWC. You can also right click each class and choose "Insert Into Document", and it will insert the full class name. If you do that, then press semi-colon enter, you will have your first class reference. Keep your mouse over the class list in the project settings and repeat this for every class in the list. It only takes a few minutes to do this for hundreds of classes, which makes creating such a list easier. It would be even faster if the thing would let you insert more than one at once, but it doesn't seem to.
Your only other option, which you said you weren't interested in for no given reason, is Runtime Shared Libraries (RSLs). It's really not that big a deal to load the file in separately, but only if you properly handle the load process and any errors that might occur. It will add some complexity to your project, and may require some extra thought, but I'd seriously consider it as an option. See the "Application Domain Inheritance" section at www.senocular.com/flash/tutorials/contentdomains/?page=2 for more information.
I am probably missing something but isn't it a case of using -include-libraries rather than library-path option of the compiler, this is what the adobe doc says about the option
Links all classes inside a SWC file to the resulting application SWF file, regardless of whether or not they are used.
Contrast this option with the library-path option that includes only those classes that are referenced at compile time.
Adobe Documentation
I am new to all this so be gentle when you shoot me down in flames :)
You can supply the path of your assets.swc file, in ActionScript Properties, and that should work and load assets at runtime.
in flex, and whenever you have access to compiler options, you can use: -include YourClass to force the linking of the class from swc even if its not referenced from the main swf.
but i dont know if you can change compiler options from flash cs4...

An extra wrapper or decorator class needed when using SWC assets?

I'm still learning how to compile with the Flex SDK. And I'm learning how to use SWC files and [EMBED] statements to pull my assets into my application.
With the Flash IDE, I can link a library asset to a class and it's automatically embedded into my custom class. So that's 1 asset in 1 class. With the Flex SDK and SWC files, it seems I can only* pull in assets at the variable level, so I end up with my custom classes containing yet another class -- this means I have an extra wrapper/decorator (whatever you want to call it) class that I didn't have when using the Flash IDE.
Is this what people typically do? Doesn't that seem superfluous?
I've read Colin Moock's 'Essential Actionscript 3.0', where he mentions something about embedding a SWF at class-level as binary data... WTF.
To associate a symbol directly to a class do like this. This works for all kinds of subclasses aswell (as long as they extend the appropriate base class):
package foo {
import flash.display.Sprite;
[Embed(source='../../../../../../assets/Assets.swf', symbol='InfoPopup')]
public class InfoPopup extends Sprite {
public function InfoPopup(){
trace("constructor!");
}
}
}
A class associated with a Flash library asset must be contained within the same SWC.
?
Then, when the SWC is compiled by Flash, it finds the associated class and binds them together?
If this is the case, then artwork and code is coupled together in the same SWC file? I thought Flex w/ SWCs was great because artwork was decoupled...?
EDIT: This is not working. The only way I can instantiate a SWC asset is if it inherits from the base class, so it seems I can't associate custom classes with SWC assets?????!!!!!!

Resources