Why does Adobe Flex strip ActionScript from Flash embed symbols when compiling? - apache-flex

I wanted an animation to dispatch custom events as it cycled. It became apparent that not even trace() was running. After some searching, I found the following at Adobe:
http://livedocs.adobe.com/flex/3/html/help.html?content=embed_4.html
"If the SWF file contains any ActionScript code, Flex prints a warning during compilation and then strips out the ActionScript from the embed symbol. This means that you can only embed the symbol itself."
I also found a work-around by Grant Skinner at:
http://gskinner.com/blog/archives/2007/03/using_flash_sym.html
So, I can proceed, but I'm still wondering. Why does mxmlc strip ActionScript from Flash compiled resources when embedding their symbols into Flex apps using metatags?

Sorry for the very late response, but since I wrote that code, I can answer. :-)
Basically, there are two answers.
For old SWF assets that contain AS2 bytecode, it was far too much work to try to convert the bytecode to AS3. I'm assuming this isn't theuse case you care about anyway.
For SWF assets linked to AS3 bytecode, the basic problem is that there is no dependency information any more, so when we clone the asset, we have no idea what else we would need to pull. Because Flash can export a SWC, I decided that this was a far more robust workflow for getting assets with code from Flash to Flex. (Take a peek inside a SWC file, and you'll see an XML file that describes the dependencies used by the linker.)

It's probably a performance issue. To load a swf resource without stripping it, load it dynamically using SWFLoader or Loader instead of embedding it.

Related

Problem While swf embedding in Flex

A problem that is waste my one hour
I am embedding swf in the flex application it works fine.
But when i embed one swf the compiler through an error
unable to resolve 'com/assets/swf/flash_ad.swf' for transcoding
Unable to transcode com/assets/swf/flash_ad.swf.
pls help me.
Actually that swf is compiled and published in older version of action script.
So when i de-compile the swf and generate my own swf with latest version of action script the problem is gone.
Anyway Thanks
Make sure your flex compiler is able to locate the swf first. Try refreshing your workspace, so compiler finds it.
Also ensure your swf is built correctly. Corrupted swf's wont get embedded.
Check if this helps: http://www.brightworks.com/flex_ability/?p=38

How to create an SWC file

All I want is to take my AS3 source code files and compile them into a SWC file.
Upon inspection, the SWC files I generate end up with some kind of timeline or spite in them when I use the Flash IDE or that Flex SDK utility "compc", and it's irritating.
Flash is timeline based; so everything in Flash uses a timeline. They hide it very well in Flex, though, so it's not obvious under the hood.
To create a SWC file in Flex, you need to use the command line compiler, although it sounds like you've already done that, so I'm unclear what your issue is.
In fact, you can build a "flex library project" in Flash builder. place your AS3 source code files in this project, it would automatic generate a swc file in which your AS3 Class;

Compiling with Flex4 SDK

I'm trying to compile an existing Flex3 project with the Flex4 SDK. I'm getting this error:
Warning: This compilation unit did not have a factoryClass specified in Frame metadata to load the configured runtime shared libraries. To compile without runtime shared libraries either set the -static-link-runtime-shared-libraries option to true or remove the -runtime-shared-libraries option.
The resulting file is roughly the same as my old Flex3 compiled .swf file. Playing the resulting .swf file in the Flash Player also gives the following errors:
An Actionscript error ocurred: VerifyError: Error #1014: Class spark.core::SpriteVisualElement could not be found
If I set the compiler attribute static-link-runtime-shared-libraries to true, then the error disappears and all is well. However, the size of the resulting .SWF is a couple of 100K's bigger. And that's not what I want.
I don't fully understand the concept of runtime shared libraries, but it seems that with the option to statically link them set to true, the libraries are included in the .swf. However, I like to exclude them from the .swf and only load the needed library at runtime, as my project seemed to do with Flex3 (I didn't know that by the way).
If I understand correctly, playerglobal.swc should hold all the necessary code for the external libraries that my .swf has to load. Do Flex4 compiled files need more libraries? Should I do something with the factoryClass in the Frame metadata tag?
I think my question boils down to this: How do I compile a Flex4 .swf that is the same size as my previous Flex3 compiled .swf?
You have to add [Frame(factoryClass="path.to.your.preloader")] to the main class (the one you set in the compiler options).
Flex3 did not use rsls by default but you could enable them. Flex4 rsls are enabled by default, see: http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7add.html
The concept of runtime shared libraries is: splitting of a part of your application that is (re)used by other apps as well, thereby only requiring the user to download it once. This won't save anything on the first download but will save on later downloads. You could possibly make your own rsl, but it's mostly the ones provided by adobe that are meant to make the difference: Since 'everybody' will use them there will be a bit chance the library you need is already present on the user's system, thereby speeding up the download-time of your app.
playerglobal.swc never contained any flex framework classes, most of them are in flex.swc and framework.swc (a standard flex 3 project also includes rpc.swc and utilities.swc - I didn't check but these probably contain some flex parts as well)
Looks like you might have project migration problems. You might want to read up on the process on:
http://www.adobe.com/devnet/flex/articles/flexbuilder3_to_flashbuilder4.html
It's a really good article with overview of different possibilities for migration, depending on the amount of Flex4 stuff you want to use.

How to customise flex sdk classes?

I have modifyed XMLEncoder class from Flex SDK (XMLEncoder.as)
After it I run my project but I don't see any changes...
What should I do to realy modify project's behaviour?
Thanks!!!
It's not usually recommended but what you are trying to do is Monkey Patching. You can just copy your modified source file into your project and then you application's XMLEncoder will overwrite the one used in Flex (because of how the Flex linker works). This doesn't work with the framework RSLs though.
If you don't see changes, this means sources aren't used - swc is used instead. To use modified sources, recreate folder structure for the class you modified and put source there. You may see a lot of errors (most of the time because include directive), this means you need to copy files needed to satisfy dependencies.
Maybe this is not the right way, but sometimes it's the only option to fix broken Flex class, so professional Flex developer masters it sooner or later :)

How to get a Flex project to load a plugin at runtime?

I'm looking to have a couple of plugins in a Flex project I'm working on. I know I can load a SWF using the SWFLoader, but I thought in Flex3 you can now have Runtime Shared Libraries or something. Does anyone have any good documentation on loading a plugin at runtime? Ideally I'd like to be able to load a plugin from a URL, then execute some code from within the plugin (e.g. add a control to the page).
You can use either Modules or RSL.
RSLs have the advantage of getting cached by flash rather than the browser so they stick around longer.
Modules are easier to create and use. I have used modules and had issues with modules failing to load (code needs to handle that case). I haven't tried RSLs yet.
Here is some documentation on creating RSLs http://labs.adobe.com/wiki/index.php/Flex_3:Feature_Introductions:Flex_3_RSLs
Note that, currently, loaded RSLs must be compiled against the very same version of the Flex framework.. if you plan for a "binary" plugin system, probably you want to wait for the Marshall plan feature to be implemented, in the next Flex version.
If you want to try a new and alternative approach, this is a application core framework modelled after java OSGi: http://www.potomacframework.org/
I haven't tried it myself, but it looks really cool!

Resources