Skip to main content
Known Participant
May 4, 2014
Answered

Storing arrays in seperate file

  • May 4, 2014
  • 1 reply
  • 689 views

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 has been closed for replies.
Correct answer Ned Murphy

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.

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
May 4, 2014

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.

Known Participant
May 11, 2014

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?

Ned Murphy
Legend
May 11, 2014

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.