Inject data in an swf at compile time - apache-flex

Is it possible to inject data, for example a collection of assets (video, images...), in an swf at compile time?
We have a flex application that needs to be able to export an swf at runtime that contains all the necessary data, because it needs to run as a standalone application (on- and offline).
The idea so far was to create a server side script that calls the flex compiler and feed it the data it needs. This approach seems to work fine using the [Embed] tag for single files, but it gets kind of messy when trying to inject collections of data that vary in length for each exported swf.
We could generate an mxml file with one embedded variable for each asset and include it at compile time, but that approach seems for from ideal.
We've looked into some actionscript bytecode libraries, but those do not seem to be fit for this.
Any suggestions or other approaches for this kind of problem?
Thx,
Bert

[Embed] is definitely the way to go. You can generate an AS file that has lots of embeds. While the generated code might be a bit ugly, you can generate a nicer api too. For example, if you want an array, generate code like this:
[Embed(...)]
private var img_0:Class;
[Embed(...)]
private var img_1:Class;
[Embed(...)]
private var img_2:Class;
public var images:Array = [img_0, img_1, img_2];
That way the only ugliness is in private variables only the code generator will see. The public variable is an array.

I'm not sure why you need to do that but i guess i'll try to generate the needed actionscript file from template or something like that and then call the flex compiler.
Hope this helps you...

try as3swfit is able to generate an swf file from an empty ByteArrayand afaik it's possible to insert embedded graphics there

Like Sam said, [Embed] could work, but what are you trying to load? My first reaction is that recompiling for every request would be a big drag on the server.

Related

what is the fastest way to get all attributes from a class?

I'm working in a tool that is supposed to generate some Java Code to accelerate part of the development based in a swing input dialog...there is no need to get any further with it so I'm going to my problem...
I need to retrieve all the attributes from a class to check whenever it is necessary to add a new one. I tried to use reflection but things started getting complicated. In order to use reflection I need to compile the class I want to get the attributes as it does not work directly from .java file, .class is required for it.
The problem is that many of the classes has a lot of dependencies! Due to some design flaws some classes are a high coupled, so if I am supposed to dynamic use a class loader to compile a class A I would have to retrieve and compile all its dependencies! And then retrieve all the possible dependencies from the class A dependency classes!
I made a test running an existing ant file to compile to whole project instead of the above approach but it takes about 9 minutes to finish! From the final user perspective waiting 9 minutes every run is not accetable!
Does any one here knows a better solution???
If you want to avoid working with reflection and bytecode, it means that you will have to parse the .java files yourself with a grammar and, well, a parser based on this grammar. It is possible (especially if you do not implement the whole grammar, because many java features might be useless in your project perimeter), but I reckon this is no easy task.
There is an Apache commons Sandbox package called ClassScan. It is capable of doing the kind of source parsing you appear to require. http://commons.apache.org/sandbox/commons-classscan/. Note that it is in the Sandbox, so not part of the Commons Proper.

Unstructured Actionscript file and ActionScript Class?

I am new in ActionScript . I want to know that when should we use an Unstructured ActionScript file and when should we make a Class of ActionScript file? Does it effect the performance of Application ?If yes , HOW??? Please help me finding the comprehensive answer of above question.
Thanks!
Regards
I can only think of a handful of instances in which it might make sense to use a non-class based structure in an ActionScript project:
You're quickly prototyping a simple piece of functionality (even then it's just as easy, assuming you're using ActionScript 3.0, to put your code in a class and set it as the Document as it is to use a non-class file via include)
You're dealing with non-class based legacy code
You're using the timeline to structure your code (usually not a great idea for anything much more complicated than a banner)
You're writing your project in ActionScript 1.0 (in which case you should really consider upgrading)
In all other cases, the tiny hit in performance resulting from the additional scaffolding of a class-based system will be more than offset by the advantages of it being well-structured.
If you're using Flex, I think you'll have to work quite hard not to use classes.

How to call calabash xml from a Java program

I try to set up a web based application using spring and xslt. Since i always use xslt in a pipelining style, i would like to use calabash. Is there a possibility to call calabash from Java? I read thru the documentation on http://xmlcalabash.com but there is only a description how to use it from command line. I also tired to find some javadoc on githup but wasn't successful. Obviously, there is the Main class with the main() method and i could supply the command line parameters as a string array...
I wonder if there is a better way to do it.
I looked into this recently too. I took a pragmatic approach where I call Main.run(), and pass in a string array that I generate from a (File)Properties object. It doesn't allow passing in file inputs as streams or sources however, they must reside on the file-system.
Likely there are nicer ways. You could for instance look into http://expath.org/ . There should be sources of that project. The webapp modules (formerly known as servlex?) seems to provide XMLCalabash integration.
HTH!

DTE: detect autogen code

I have a small Visual studio add-in that walks down active project and insert code to every method.
My target project has web service reference and it created a bunch of auto-generated refenrece files that I do not care about.
Is there a way to detect whether a projectitem is autogen file?
The project file has tag under but ProjectItem.Properties doesn’t have it.
Thanks
Is there a way to do this 100% reliably? I don't think so. The only way I've ever been able to tell if a file is autogenerated or not is by its content or by its filename.
Often, generated code files in newer versions of (what I know) C# have a ".g." within their names. This is not written in stone or guaranteed (I think windows forms and other older generators use ".Designer."), but it can be used as an indication.
If you look through different autogenerated code, you'll see there are a number of different ways it can be marked. There is no specific way that is universal. For example, autogenerated wire-up code in WPF codebehind files (the hidden InitializeComponent() method resides there) contains a partial class definition marked with the System.CodeDom.Compiler.GeneratedCodeAttribute and the methods are all marked with the System.Diagnostics.DebuggerNonUserCodeAttribute.
The first attribute resides on the class, so it may show up when inspecting the code via EnvDTE methods. You might have to resort to reading the file in raw and looking for that attribute.
Even this isn't enough information, as different code generators mark their code differently. Type safe DataSets and EF generated code mark their generated code with a comment at the top of the file
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.551
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
What now?
Unless you explore all the different ways autogenerated code is marked, and handle them all, there isn't any way (unless I'm missing something!) you can guarantee skipping these files. You have to ask yourself if it is worth the effort.

How can I best convert an AS1/AS2 application to an ActionScript3 application?

I have a program consisting of multiple SWF's. An AS2-SWF loads a bunch of AS1-SWFs.
It's a crappy program. I'd like to specify the GUI in MXML and perhaps refactor some code to AS3. However, converting all of the 300+ symbols to AS3 or whatever is undoable.
What are my options in converting to AS3/Flex/MXML? The app is very simple, only also quite large. It consists only of buttons, backgrounds and attention-texts. All the button texts are in XML files.
I want to turn this into pretty code ASAP but also controlled so the code becomes:
easily updateable/maintainable,
readable
learnable (so I can have the updating done by someone that can only script AS3 or even MXML).
Of course doing this is on my own initiative, if it'll take more than a week, I won't be able to find the time.
Regards, Jurgen
This might help:
http://flexman.info/2009/03/29/as3converter-an-ant-task-small-collection-of-as3/
It's mainly for AS2 code, so FLA editing is out of the question. But you should certainly look into JSFL.
There are some pretty good scripts out there already dealing with something like this:
http://bumpslide.com/blog/2009/03/07/jsfl-class-generator/
What this command does is that it
looks through your library and finds
all library items that have a custom
linkage class name. If the class
extends flash.display.MovieClip (or if
the base class is blank), it checks to
see if a classfile exists, and if not,
it creates it for you. When it does
this, the script looks at all the
items on the timeline and adds
relevant properties to your class. If
these clips are instances of other
components, they will be typed as
such, and relevant import statements
will automatically be added to your
class. If your component is set to
extend some other class (for instance,
com.bumpslide.ui.Button), no class
will be generated. Class files will be
written to the correct package
location inside the first custom class
path defined in your publish settings.
Jurgen, I feel for you... it sounds like a lot of work.
What sorts of issues do you have? are all the swfs treatable as different classes? is there much overlap in the logic or does each object have a specific role?
I think having so many different SWFs may possibly lead to scoping problems> which swf talks to which. you may be able to set up something with as3 that uses the existing parts and then try making a facade over the existing code > use the existing logic in the swfs and do the visual part through mxml. other than that, all I can advise is a rebuild. you might find yourself in need of a swf decompiler too if you are missing some of the original fla's

Resources