Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411490 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 24, 2024, 05:31:41 PM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Embedding XML files in AS3?
Pages: [1]
Print
Author Topic: Embedding XML files in AS3?  (Read 13625 times)
Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« on: May 12, 2009, 11:33:26 AM »

So I want to include XML files in my SWF as level data files.

Here's where I'm embedding the file:
Code:
package 
{

public class Levels
{

[Embed(source = '../../../../assets/levels/test.xml')]
public static const Level_Test:Class;

}

}

And here's where I'm trying to use it:
Code:
var xml:XML;
var file:Class;

file = new Levels.Level_Test();
xml = file;

...parse the XML...

Obviously I have no clue what I'm doing.  I also tried using "xml = file.data;" to no avail.  How do I translate file to an XML object?

The weird part is that I'm getting syntax errors from the XML file when I try to compile this  Shrug

Quote
Error: Syntax error: expecting semicolon before xmltagstartend.
<WIDTH>30</WIDTH>

(No, the XML file is not in my source folder - it is in my assets folder so it shouldn't be trying to compile it that I know of)

« Last Edit: May 12, 2009, 11:50:09 AM by Matt Thorson » Logged

Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #1 on: May 12, 2009, 12:04:02 PM »

I found the solution to this slumming through blog comments.  In case anyone else runs into this problem I'll post the solution here.

Here's the link to where I found it: http://dispatchevent.org/roger/embed-almost-anything-in-your-swf/comment-page-1/

Basically, embedding XML is broken or something Shrug So you have to embed it with the MIME type "application/octet-stream", then on load read all the bytes into a string and convert that string to an XML object.

Code:
[Embed(source='../../../../assets/levels/test.xml', mimeType="application/octet-stream")]
public static const Level_Test:Class;

Code:
var ba:ByteArray = (new Levels.Level_Test()) as ByteArray;
var s:String = ba.readUTFBytes( ba.length );
xml = new XML( s );

Logged

agj
Level 10
*****



View Profile WWW
« Reply #2 on: May 13, 2009, 09:48:28 AM »

Thanks! I'd been thinking about this as a way to store dialog lines and level data, but so far hadn't wanted to investigate how to do it.
Logged

Loren Schmidt
Level 10
*****



View Profile WWW
« Reply #3 on: July 16, 2009, 06:38:44 PM »

Pardon my resurrecting an old thread- I have a few questions related to the original post:

I'm making a game which stores its levels in xml format. This makes level editing convenient, because I can edit and reload an area without recompiling. Unfortunately I'm under the impression that I'll need to embed all external files into the .swf for it to be Flash portal friendly, thus losing the flexibility of using xml files in the first place. Is this correct?
Logged
Kunal
Level 1
*


is feeling Bit.Core.Trippy


View Profile WWW
« Reply #4 on: July 16, 2009, 07:10:09 PM »

Pardon my resurrecting an old thread- I have a few questions related to the original post:

I'm making a game which stores its levels in xml format. This makes level editing convenient, because I can edit and reload an area without recompiling. Unfortunately I'm under the impression that I'll need to embed all external files into the .swf for it to be Flash portal friendly, thus losing the flexibility of using xml files in the first place. Is this correct?

AFAIK, thats how it works. Most sites don't like having to deal with multiple files for a single game. Even if you do offer to host the XML files (and other external files) for them, they may not be willing since the game would be crippled/unplayable in case your host went down.

Maybe things have changed though. In case you don't get any more replies here, it might be worth asking someone on the forums at MochiAds or flashgamelicense
Logged

Matt Thorson
Level 7
**

c'est la vie


View Profile WWW
« Reply #5 on: July 16, 2009, 09:13:11 PM »

I wrote this tutorial detailing how I did the XML stages for MoneySeize: http://mattmakesgames.com/blog/2009/06/embedding-xml-in-as3.html
Logged

Titch
Level 3
***


Cautiously Pragmatic


View Profile WWW
« Reply #6 on: July 17, 2009, 05:19:55 AM »

Pardon my resurrecting an old thread- I have a few questions related to the original post:

I'm making a game which stores its levels in xml format. This makes level editing convenient, because I can edit and reload an area without recompiling. Unfortunately I'm under the impression that I'll need to embed all external files into the .swf for it to be Flash portal friendly, thus losing the flexibility of using xml files in the first place. Is this correct?

Yes, most portal want to have a single swf file.

There isn't anything to stop you from using your current model though. Just embed the xml file as described and code in a 'dev-mode' boolean that when switched on forces flash to load the xml file instead of the embedded stream. If both bits of code point to the same file you can edit and refresh a level without compiling the entire app, but when you do compile it will insert the newest version.

Just don't forget to disable the development mode flag on the release version. I have a feeling theres even a function in flash to check if you are running the debug flash player. Which would be a great way of switching development functions on and off.
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic