hi there!
this is my first AS3 post ever as i am trying wrap my PHP brain around AS3.
i am desperately trying to find a way to make my config array work…
DREAM is to import XML and to ideally create a 3 dimensional associative array…
aConfig[container_id][slot_id][width] = 45;
i understand tho that in REALITY i must find a way to cheat:
aIndex[container_id][slot_id] = counter;
aConfig[counter][width] = 45;
but i am trying for 3 FULL WORK DAYS now to figure out why this is not working.
error message is
TypeError: Error #1010: A term is undefined and has no properties.
at sonicticker_fla::MainTimeline/xmlLoaded()
at flash.events::EventDispatcher/flash.events:EventDispatcher::dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/flash.net:URLLoader::onComplete()
so if one of you AS3 gurus could give me a hand it would be extremely appreciated as i doubt that my employer will have any more patience with me.
// LOAD XML
var xmlList:XMLList;
var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("myFeed.xml"));
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, catchIOError);
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
function catchIOError(event:IOErrorEvent) {
trace("XML Error caught: "+event.type);
}
function xmlLoaded(event:Event):void {
var xmlDataAll:XML = XML(event.target.data);// getting the data from the assigned variable
var keyCounter:Number = 1;
var configArray:Array = new Array();
var configIndex:Array = new Array();
// get the amount of existing <feed> children in this <root> tag
for (var n:int = 0; n < xmlDataAll.child("feed").length(); n++) {
// the container and slot ids of this row
var container:Number = xmlDataAll.child("feed")[n].@container ? xmlDataAll.child("feed")[n].@container : 0;
var slot:Number = xmlDataAll.child("feed")[n].@slot ? xmlDataAll.child("feed")[n].@slot : 0;
// trace(container + " " + slot); // WORKS!
configIndex[ container ][ slot ] = keyCounter;
// for each row in this feed
for (var k:int = 0; k < xmlDataAll.child("feed")[n].@*.length(); k++) {
var row:Array = new Array();
var contentAttribute:Object = xmlDataAll.child("feed")[n].attributes()[k].name() ? xmlDataAll.child("feed")[n].attributes()[k].name() : "nothing";
var contentValue:String = xmlDataAll.child("feed")[n].attributes()[k] ? xmlDataAll.child("feed")[n].attributes()[k] : "nothing";// get all values
// trace(contentAttribute + ": " + contentValue); // WORKS!
row[ contentAttribute ] = contentValue;
configArray[ keyCounter ].push(row);
}
trace(configArray[ keyCounter ]["itemSource"]);
keyCounter++;
}// end for
}
the xml:
<root>
<feed container="1" slot="1" itemType="video" itemSource="thumbnails/1.jpg" itemWidth="458" itemHeight="458" fromLeft="67" fromTop="78" />
<feed container="1" slot="2" itemType="video" itemSource="thumbnails/2.jpg" itemWidth="458" itemHeight="1222" fromLeft="45" fromTop="6565" />
<feed container="2" slot="1" itemType="text" itemSource="blah rhabarber" itemWidth="458" itemHeight="23434" fromLeft="76" fromTop="565656" />
<feed container="2" slot="2" itemType="text" itemSource="find me" itemWidth="458" itemHeight="34" fromLeft="65" fromTop="6666" />
<feed container="2" slot="3" itemType="date" itemSource="another textbox" itemWidth="458" itemHeight="23" fromLeft="34" fromTop="777" />
<feed container="2" slot="4" itemType="text" itemSource="a thid box" itemWidth="458" itemHeight="458" fromLeft="47" fromTop="58" />
</root>
thank you!
magenta