Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Creating array from XML file

New Here ,
Nov 18, 2011 Nov 18, 2011

Currently my application uses the following arrays to populate a map with data depending on the user's selection.

<fx:Declarations>

<fx:Array id="fwo1">

<ammap:MapArea instanceName="borders" color="#FFFFFF" mouseEnabled="false"/>

<ammap:MapArea instanceName="SE" title="SWEDEN" value="4447100" customData="{dpSE}"/>

<ammap:MapArea instanceName="CH" title="SWITZERLAND" value="47100" customData="{dpCH}"/>

<ammap:MapArea instanceName="FR" title="FRANCE" value="447100" customData="{dpFR}"/>

</fx:Array>

<fx:Array id="fwo2">

<ammap:MapArea instanceName="borders" color="#FFFFFF" mouseEnabled="false"/>

<ammap:MapArea instanceName="SE" title="SWEDEN" value="2000" customData="{dpSE}"/>

<ammap:MapArea instanceName="CH" title="SWITZERLAND" value="200" customData="{dpCH}"/>

<ammap:MapArea instanceName="FR" title="FRANCE" value="20" customData="{dpFR}"/>

</fx:Array>

</fx:Declarations>

I would like to spin the country data off into one or more external XML files so that rather than being hard coded, the arrays would load the data dynamically.

<fx:Array id="fwo1">

<ammap:MapArea instanceName="borders" color="#FFFFFF" mouseEnabled="false"/>

[[include/loop through data from XML file to create rest of array]]

</fx:Array>

<fx:Array id="fwo2">

<ammap:MapArea instanceName="borders" color="#FFFFFF" mouseEnabled="false"/>

[[include/loop through data from XML file here to create rest of array ]]

</fx:Array>

After much searching, I just haven't quite found an example that will let me make the leap from hard coding to dynamically loading the data (in large part, because of the name space declaration as part of the array element).

Any suggestions would be greatly appreciated.  Thanks so much.

TOPICS
ActionScript
910
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Nov 18, 2011 Nov 18, 2011

I suggest you search Google using terms like: "AS3 XML tutorial".  You should find a number of them.  In looking at what you are calling your arrays, I would have already thought they are xml file contents.  So unless I am missing something, you probably just need to get that into an xml file (possibly with some adjustments) and just process that data into your Flash file dynamically. 

I will normally read/parse xml data into arrays, so you shouldn't have much trouble doing that if you find a tutorial that walks you thru it.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Nov 19, 2011 Nov 19, 2011
LATEST

Hi laurie brown,

////////////////////// XML /////////////////////

<?xml version="1.0" encoding="iso-8859-1"?>

<Data>

<name>Raj</name>

<name>Siva</name>

<name>Babu</name>

<name>Kiran</name>

<name>Girish</name>

</Data>

////////////////////// XML /////////////////////

////////////////////// As 3.0 /////////////////////

package{

    import flash.display.MovieClip;

    import flash.net.URLLoader;

    import flash.net.URLRequest;

    import flash.events.Event;

    public class XMLDataPush extends MovieClip{

        var urlRequest:URLRequest = new URLRequest("data.xml");

        var urlLoader:URLLoader = new URLLoader();

        var dataArr:Array = new Array();

        public function XMLDataPush():void{

            urlLoader.load(urlRequest);

            urlLoader.addEventListener(Event.COMPLETE, onLoaded);

        }

       

        private function onLoaded(evt:Event):void{

            var xml:XML = new XML(evt.target.data);

            for(var i:Number = 0; i<xml.children().length(); i++){

                dataArr.push(xml.children());

            }

            trace(dataArr + "  dataArr" );

        }

       

    }

}

////////////////////// As 3.0/////////////////////

If it use for you please mark it correct answer.

Thank you

Siva

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines