reading simple INI file with AS3 - apache-flex

What AS3 class should I use to read a simple property/ini file into memory to configure some settings such as colors easily for the project.
format could be
key=value <newline>
I like to access it with this kind of API: trace ( Settings.get("key") )

There is no built-in way to do this in AS3, but we have support for loading and parsing properties files in Spring ActionScript.
Here are the direct links to the sources:
Properties
PropertiesParser (used internally in Properties)

I you can choose your format freely XML is very easy to deal with in actionscript3, it might not be perfect for super simple config files, but it's extremely easy to handle once you get it in.
This page looks to have a reasonable overview: http://dispatchevent.org/roger/as3-e4x-rundown/

Related

Inject data in an swf at compile time

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.

HTTPService resultFormat, how to choose

HTTPService has a property resultFormat which can be set to any of the following: array e4x flashvars object text xml
I looked at the documentation to understand the difference, but still couldn't understand when to use each. I'm looking for the lightest weight of all of them.
P.S. I'm consuming output from my own server, so can change the output format as needed to make it compatible with each.
Most of the time either object or e4x is used. The "object" option automatically converts XML to ActionScript objects. This is usually my preferred way to load data from a server when using HTTPService. The e4x option keeps the XML data as XML and then uses the EcmaScript 4 XML notation to query / modify the XML structure. I personally find e4x painful to debug so I usually avoid it.
If you are looking for great performance then you should consider using AMF instead of XML. There are numerous open source server-side implementations of AMF. So picking one depends on your back-end. No matter which one you choose you will likely use the RemoteObject library instead of HTTPService.
There are examples of HTTPService and RemoteObject in Tour de Flex.

Programmatically generate InfoPath form template?

Is it possible to programmatically generate an info path 2007 form template (xsn file=form definition) ?
I know that there is no object model for the infopath 2007 form designer, but does anyone know of any third party libraries?
The form view itself is a xsl file so it should be possible. I would have thought that its a common use case also.
It is possible to generate the manifest.xsf, xsl and xml files from a structured source (let's say an xml) and then pack this (as .cab) with the extension .xsn
(The .xsn file is nothing but a renemed .cab!)
This is only a raw concept - it could be refined if the purpose was a bit more explicit. Why generate? Are you going to create a bunch of different files? What for?
There are no libraries or API's to do this. While generating a template is possible you will need to write it all yourself. Obviously this will not be an easy task and will be prone to errors. I would recommend reviewing your requirements to ensure this is truly necessary. InfoPath is quite flexible, without knowing the details of your project, there is a good chance you can get the functionality you need with a single template.

How to go from xsd schema to Actionscript object (Flex) at runtime?

I have seen questions here asking about xsd->actionscript objects, but these seem to require xsd->java->actionscript and is all in source code. Our requirements are a bit different:
receive an xsd during runtime that we have never seen before
Create an instance object based on the xsd
fill in the values of the instance (either from an xml document or user input - whatever)
Anyone know of an actionscript library or tool that would help us accomplish this at runtime? It would be nice if something like this already existed - but we would certainly settle for a library that gave us a programmatic interface to extract information from an xsd schema. Additionally, we would take suggestions on alternate methods to accomplish the same ends.
Have you looked at the SchemaLaoder...? Not EXACTLY what you're looking for ... But a great start.
First - you should check this blog entry and this blog entry which walks you through Dominic De Lorenzo experiences with utilising functionality within the Flex SDK that provides the automatic mapping of custom ActionScript classes to element definitions within an XML Schema (XSD).
The steps to get moving here include (from Dominic's blog):
0) Create an instance of SchemaLoader and asynchronously load an XML schema from a given URL
1) Once the schema is loaded, add it to the SchemaManager and register any ActionScript classes to their corresponding schema type
---- At this stage you can do several operation based on the schema
2) Load an XML file based off that schema
3) Once the XML is loaded, decode the contents using XMLDecoder. Any classes registered in the schemaTypeRegistry will be used when decoding the xml
4) Encode a custom ActionScript class back into XML using XMLEncoder. XMLEncoder.encode() supports various ways to define the corresponding element in the schema (top level element, a specific type or even a custom XSD definition) that will be used to encode the Actionscript object.
The blog entry has links to code samples, etc...
Hope this helps.

How do I connect (and use content of) an RDF file in Flex?

I'm working on a prototype in flex and I need to connect my application to an .RDF file that contains some properties. I need to use and manipulate those properties in a "descriptor file" made in Actionscript. So my question is: how do I connect my flex application to that .RDF file?
Thanks,
regards
David
If RDF is represented in its XML form (which I guess is the most common anyway), you can simply treat it as XML and use the built-in XML and XMLList classes, and the rather convenient E4X (ECMAScript for XML) syntax to traverse your document. To load the RDF file from the server or from another remote location, use the URLLoader class.
If, on the other hand, the RDF uses some other representation, you'll probably have to do the parsing from plaintext yourself. (You can still use URLLoader).

Resources