Question

I have a .fla that gets opened up, a few actionscript variables (a url, title etc.) are changed, and published. This happens a lot, and it's the same variables. I would just keep the .swf file with an XML file, but it being uploaded to a third-party platform, so all of the information needs to be contained in the .swf file. There is no way to add the variable information to the third-party site.

I want to know if there's a way to take the new variable information from an xml file or something at publish time (like a script?) without having to open up the Flash IDE. To be able to do a bunch of these at once would also be great.

Any help/links/leads would be appreciated. Google did not help me. Is this even possible?

Was it helpful?

Solution

Without opening the Flash IDE would require loading external resources or a build script using ANT or simply with the mxmlc compiler, something to the effect of:

mxmlc -o output.swf -source-path="src/" -library-path+=library.swc. 

As you indicate embedding XML at compile time, you could either embed the XML using the [Embed] metadata tag or paste your XML in a class.

Embed XML

package
{
    public class XmlData
    {
        [Embed(source = "data.xml", mimeType = "application/octet-stream")]
        public static const Xml:Class;
    }
}

To use the XML, instantiate the xml as:

var xml:XML = new XML( new XmlData.Xml );

XML variable

Otherwise, you can simply paste your xml in a class like so:

package
{
    public class XmlData
    {
        public static const xml:XML =
            <root>
                <element />
                <element attribute="value">data</element>
            </root>;
    }
}

Although you must compile your SWF, this approach is easy because you can simply paste your XML document to the class.

This would be referenced as normal with e4x and no asynchronous load required.

var data:String = XmlData.xml.element.@attribute;
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top