Skip to main content
Known Participant
May 4, 2014 10:02 AM UTC
Answered

Storing arrays in seperate file

Hello I am making a maze game in actionscript 3. For each level i have a two dimensional array like this one (but much bigger):

var Maze_1:Array = [

[1,1,0,0,0,0],

[0,1,1,0,0,0],

[0,0,0,1,0,0]

];

In my MainClass i have a variable called currentMaze. I want to set that variable to the maze of the currentLevel. How would I make a seperate file containing all the mazes and then load them in the MainClass?. I've heard about some people using XML but i have never used it so i don't know anything about it. Is there a more simple way to this?

This topic is closed to new replies. Start a new post to keep the conversation going.
Ned Murphy
Ned MurphyCorrect answer
Legend
May 4, 2014 12:05 PM UTC

If you search Google using terms like "AS3 XML tutorial" you should find plenty of results to walk you thru making use of it in your file.  You will not regret adding this to your toolset.

Another way would be to store as a separate text file (.txt), where you end up having to perform similar extractions as you would for an xml implementation, though xml can make it easier to do.

9 replies

Ned Murphy
Ned MurphyCorrect answer
Legend
May 4, 2014 12:05 PM UTC

If you search Google using terms like "AS3 XML tutorial" you should find plenty of results to walk you thru making use of it in your file.  You will not regret adding this to your toolset.

Another way would be to store as a separate text file (.txt), where you end up having to perform similar extractions as you would for an xml implementation, though xml can make it easier to do.

Translate
Known Participant
May 11, 2014 3:47 PM UTC

Okay I have looked into the basics of XML and decided that I will use it for my project. I now know how to load the XML data into my flash project using the URLLoader function. I have made a small XML document which looks like this:

<LevelManager>

    <Levels>

        <Maze>

        [

            [0,0,0,0,0,0,0,0],

            [1,1,0,0,0,0,0,0],

            [0,1,1,0,0,0,0,0],

            [0,0,1,0,0,0,0,0]

        ];

        </Maze>

    </Levels>

</LevelManager>

But when i load this data of Maze into my flash file and use it as an array it doesn't work. I guess this is because you cannot declare an array like this in an XML document. How can i declare my array in an XML document and load it into flash?

Translate
Ned Murphy
Legend
May 11, 2014 3:53 PM UTC

XML is a tag-based form of text-based documentation. You can define each value of the array as a separate tag, or you can define each subarray as a string and when you parse it you split on the commas, or you could mash the whole array into a single string with commas between elements of subarrays and some other delimiter between subarrays.

Translate