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?
Related
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.
There are three modes to link an SWC library to a flex application: "Merged into code", "External" and "RSL". I understand what is "RSL", but I don't understand what is "External".
"RSL" works just fine for me, without any code changes. However, External doesn't work for me. Although my application starts, the classes in the SWC set to External are never found.
What is the meaning of "External" if it is not "RSL" ? How do I make use of that ?
Thank you,
Boris
Defining a class as External allows the Flex compiler to link to a particular class at compile time but does not cause it to be included in the generated SWF.
The general use for External classes is where you have multiple modules that use a shared library. It would be redundant to include the shared class definitions in every single module and the External keyword allows you to control how these classes are compiled into your libraries.
More information is available at the following locations:
http://web.archive.org/web/20101007120528/http://www.wannaknowflex.com/2010/05/flex-linkage-difference-between-rsl-and-external/
http://www.flexafterdark.com/docs/Flex-Libraries
(external-library-path and load-externs compiler information):
http://www.newtriks.com/?p=802
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
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...
Here's a dumb question. I compile my Flex application with several swc's (libraries) and it creates a swf file. The sum of the swc's is roughly 4 MB yet the actual swf generated is only 1.6 MB. How is this possible?
Thanks!
The compiler only compile classes from the swc that your application need, unless you specify which classes you want to 'embed'. Hence the smaller size of the swf at the end.
To expand on PeZ's response a bit, typically SWCs supplied to the Flex application compiler using the "library-path" compiler argument:
library-path path-element [...]
Links SWC files to the resulting application SWF file. The compiler only links in those classes for the SWC file that are required. You can specify a directory or individual SWC files.
You can use "include-libraries" instead:
include-libraries library [...]
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.
You'll typically want to use "library-path" to help keep the size of your SWF as small as possible. However you may need to use "include-libraries" if your application instantiates classes from a SWC via reflection only. Since these classes are not actually linked to in the application, they won't be included if you use "library-path" to reference the SWC, and you'll get a runtime error during instantiation since the type is not available. However if you use "include-libraries" the class (and all other classes in the SWC) will be available to the app.
1) in swf file only required classes are included
2) more files result in additional header information that will also increase size slightly.
To reduce the size of flex swf you can use these techniques mentioned in this article :
http://askmeflash.com/article_m.php?p=article&id=9