开发者

Can I retain xml data in a .swf?

I have a .swf file that has all of its assets loaded through xml to make the file modular. However, when I try moving the published .swf file to a different directory, I need to bring the xml file and all the assets along as extra baggage.

Is there any way to create a .swf that can load these assets during publish, and retain them? I'm currently trying to make another .swf, load it into that o开发者_JAVA技巧ne, and using Adobe Air to update it with everything loaded, but I don't think this is the right direction.

I would prefer to avoid using a wrapper, but if there is no other option I will look into it.


You can embed the XML in to the compiled SWF:

[Embed(source="data.xml", mimeType="text/xml")]
protected const XmlClass:Class;

var xml:XML = XML(new XmlClass());
trace(xml.toXMLString());

Or, you could simply paste the XML as a member of an ActionScript class:

package
{

    public class XmlData
    {

        public static var xml:XML =
            <root>
                <child name="etc..." />
            </root>;
    }
}

Hope that helps.


Look into ".sol" files. they are more or less a variable database for Flash files (some flash games use them to store your information for future visits). The only problem is that if you move the program to another computer, it would have to move as well. Other than that, I know of no other way, but perhaps someone else might?

Edit: after-thought -- perhaps it would benefit you to look into using a remote SQL database to store your information?


Jason is right. You could also embed (include in the compiled .swf file) your bitmap assets using

[Embed(source="asset.jpg")]
private var BitmapAssetClass:Class    

var myBitmapInstance1:Bitmap = new BitmapAssetClass();
var myBitmapInstance2:Bitmap = new BitmapAssetClass();

or the .swf vector assets using:

[Embed(source="assetLibrary.swf", symbol="myFlashCS4SymbolName")]
private var VectorAssetClass:Class    

var myVectorInstance1:Sprite = new VectorAssetClass();
var myVectorInstance2:Sprite = new VectorAssetClass();

addChild(myVectorInstance1);
addChild(myVectorInstance2);

This would end modularity and every time you'd want to add an individual asset change you would have to compile the whole application again.

hth

N.B.: compile = publish

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜