<calendar>
<category>
<catName>PREPARING THE ORGANISATION FOR BLOCKBUSTER LAUNCH</catName>
<catColour>0x860038</catColour>
<Events>
<EV name="TEST1">
<eventMonts>
<Jan>
<entry>FDA 789</entry>
<objective>My Objective</objective>
<desc>My Description</desc>
<details>My Details</details>
<attendance>Philip,Gayle</attendance>
<date>28 Jan 2009</date>
<venue>My venue</venue>
<notes>My Notes</notes>
<hqcontact>Joe Soap IDIOT Mother</hqcontact>
</Jan>
<Feb>
<entry>Feb FDA</entry>
<objective>Feb Not Now</objective>
<desc>Feb My Description</desc>
<details>Feb My Details</details>
<attendance>Feb Philip,Gayle</attendance>
<date>Feb 28 Jan 2009</date>
<venue>Feb My venue</venue>
<notes>Feb My Notes</notes>
<hqcontact>Feb Joe Soap HQ Contact Dude</hqcontact>
</Feb>
<Mar>
<entry>Mar FDA</entry>
<objective>Mar objective</objective>
<desc>Mar My Description</desc>
<details>Mar My Details</details>
<attendance>Mar Philip,Gayle</attendance>
<date>Mar 28 Jan 2009</date>
<venue>Mar My venue</venue>
<notes>Mar My Notes</notes>
<hqcontact>Mar Joe Soap HQ Contact Dude</hqcontact>
</Mar>
var caldata:Array = temp.childNodes;
//trace("XML DATA+++> : "+caldata);
for (icd=0; icd<caldata.length; icd++) {//iterate through each <categorysection> node
//trace("subcat->: "+subcategories[isc].attributes.name);
trace("-----------------------------------------------------------------------------");
trace("Event name: "+caldata[icd].firstChild.childNodes[0].childNodes[0].nodeValue);
trace("objective name: "+caldata[icd].firstChild.childNodes[1].childNodes[0].nodeValue);
trace("desc name: "+caldata[icd].firstChild.childNodes[2].childNodes[0].nodeValue);
trace("details name: "+caldata[icd].firstChild.childNodes[3].childNodes[0].nodeValue);
trace("attendance name: "+caldata[icd].firstChild.childNodes[4].childNodes[0].nodeValue);
trace("date name: "+caldata[icd].firstChild.childNodes[5].childNodes[0].nodeValue);
trace("venue name: "+caldata[icd].firstChild.childNodes[6].childNodes[0].nodeValue);
trace("notes name: "+caldata[icd].firstChild.childNodes[7].childNodes[0].nodeValue);
trace("hqcontact name: "+caldata[icd].firstChild.childNodes[8].childNodes[0].nodeValue);
trace("-----------------------------------------------------------------------------");
}
//here just generic movieclip created
mc=_root.createEmptyMovieClip("mc-"+_root.getNextHighestDepth(), _root.getNextHighestDepth());
mc.beginFill( 0x000000);
mc.moveTo(0, 0);
mc.lineTo(100, 0);
mc.lineTo(100, 100);
mc.lineTo(0, 100);
mc.lineTo(0, 0);
mc.endFill();
//this stuff you should do in your loop
//onRelease will be called when user press movieclip mc
mc.my_data="xml data or other object";
mc.onRelease=function(){
trace(this);
trace(this.my_data);
}
var currentmonth=0;
var currentcat=0;
var currentrow=0;
var counter=0;
var xml:XML = new XML();
xml.ignoreWhite = true;
xml.onLoad = function() {
setProperty(square, _x, 0);
setProperty(square, _y, 0);
var curY=0;
var curX=0;
var curXWidth=0;
var setWidth=0;
var setHeight=0;
var setSpacer=0;
setSpacerX=0;
setCatHeight =20;
setSubCatHeight =20;
setMonthsHeight =60;
setProperty(square, _height,setCatHeight);
var catTextFormat = new TextFormat();
//trace(">>>START BUILDING CALENDAR>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>");
//===============Loop through the Main Categories=================================
var categories:Array = this.firstChild.childNodes;//get the main <category> nodes in a array
setWidth =115;
for (i=0; i<categories.length; i++) {//iterate through each <categorysection> node
var catname = categories[i].childNodes[0].firstChild.nodeValue;//<categories>
var catcolours = categories[i].childNodes[1].firstChild.nodeValue;//<entry>
var cattextcolours = categories[i].childNodes[2].firstChild.nodeValue;//<entry>
//trace("Main Category Name:"+catname+"=====================================");
//SUPRESS ROW IF CATEGORY IS BLANK
if(catname=="none"){
}
else
{
catTextFormat.size = 30;
catTextFormat.color = cattextcolours;
catTextFormat.bold = true;
//catTextFormat.font = "arial";
currentmonth=0;
duplicateMovieClip(square, "csquare"+counter, counter);
setProperty("csquare"+counter, _x, 0);
setProperty("csquare"+counter, _y, (Number(getProperty("csquare"+(counter-1), _y))+Number(getProperty("csquare"+(counter-1), _height))));
setProperty("csquare"+counter, _width,990);
setProperty("csquare"+counter, _height,setCatHeight);
//trace("Cat Y: = (Previous Y("+ Number(getProperty("csquare"+(counter-1), _y))+") + Cur Height ("+Number(getProperty("csquare"+counter, _height))+")) * Row ("+currentrow+")");
//trace("Category : "+ catname +" [Counter:"+counter+" |Row: "+currentrow+"]");
_level0.ScrollPane1.spContentHolder["csquare"+counter].varheading = catname;
_level0.ScrollPane1.spContentHolder["csquare"+counter].catName = "PHILIP DATA";
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading.setTextFormat(catTextFormat);
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading._x=0;
//_level0.ScrollPane1.spContentHolder["csquare"+counter].ojSquareData.newProperty = "HELLO THIS IS MY VALUES";
var obj:Object = new Object();
obj.category = catname;
obj.subcategory = "none";
obj.eventname="eventname1";
obj.monthvalue="Jan";
colCat = new Color(_level0.ScrollPane1.spContentHolder["csquare"+counter].sqbkg_mc);
colCat.setRGB(catcolours);
colSquare = new Color(_level0.ScrollPane1.spContentHolder["csquare"+counter].catcolor_mc);
colSquare.setRGB(catcolours);
counter = counter+1;
currentrow = currentrow+1;
}
//===============Loop through SUB CATEGORIES ==========================================
var subcategories:Array = categories[i].childNodes[3].childNodes;//get the main <category> nodes in a array
for (isc=0; isc<subcategories.length; isc++) {//iterate through each <categorysection> node
//trace("subcat->: "+subcategories[isc].attributes.name);
setWidth =115;
var subcatname = subcategories[isc].attributes.name;
if(subcatname=="None"){
}
else
{
catTextFormat.size = 30;
catTextFormat.color = catcolours;
catTextFormat.bold = true;
duplicateMovieClip(square, "csquare"+counter, counter);
setProperty("csquare"+counter, _x, 0);
setProperty("csquare"+counter, _y, (Number(getProperty("csquare"+(counter-1), _y))+Number(getProperty("csquare"+(counter-1), _height))));
setProperty("csquare"+counter, _height,setSubCatHeight);
setProperty("csquare"+counter, _width,990);
//trace("Cat Y: = (Previous Y("+ Number(getProperty("csquare"+(counter-1), _y))+") + Cur Height ("+Number(getProperty("csquare"+counter, _height))+")) * Row ("+currentrow+")");
//trace(" >>>Sub Category : "+subcatname+" Counter:"+counter+" Row: "+currentrow);
_level0.ScrollPane1.spContentHolder["csquare"+counter].varheading = subcatname;
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading.setTextFormat(catTextFormat);
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading._x=0;
//colCat = new Color(_level0.ScrollPane1.spContentHolder["csquare"+counter].sqbkg_mc);
//colCat.setRGB(0xFFFFFF);
//colSquare = new Color(_level0.ScrollPane1.spContentHolder["csquare"+counter].catcolor_mc);
//colSquare.setRGB(0xFFFFFF);
counter = counter+1;
currentrow = currentrow+1;
}
//===============Loop through the Events for Categories=================================
var events:Array = subcategories[isc].childNodes[0].childNodes;//get the main <months> nodes in a array
//trace("XML >> "+events);
//EVENTS VALUES - categories[i].childNodes[2].firstChild.attributes.name
for (ie=0; ie<events.length; ie++){
setWidth =115;
var eventName = events[ie].attributes.name;
//trace("events name :"+eventName);
catTextFormat.size = 10;
catTextFormat.color = 0x000000;
catTextFormat.bold = false;
duplicateMovieClip(square, "csquare"+counter, counter);
setProperty("csquare"+counter, _x, 0);
setProperty("csquare"+counter, _y, (Number(getProperty("csquare"+(counter-1), _y))+Number(getProperty("csquare"+(counter-1), _height))));
setProperty("csquare"+counter, _height,setMonthsHeight);
setProperty("csquare"+counter, _width,setWidth);
//if(eventName=="none"){
//_level0.ScrollPane1.spContentHolder["csquare"+counter].varheading = " ";
//}
//else
//{
_level0.ScrollPane1.spContentHolder["csquare"+counter].varheading = eventName;
//}
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading.setTextFormat(catTextFormat);
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading._x=0;
//colCat = new Color(_level0.ScrollPane1.spContentHolder["csquare"+counter].sqbkg_mc);
//colCat.setRGB(0xFFFFFF);
//colSquare = new Color(_level0.ScrollPane1.spContentHolder["csquare"+counter].catcolor_mc);
//colSquare.setRGB(0xFFFFFF);
counter = counter+1;
//currentrow = currentrow+1;
//===============Loop through the MONTHS for the EVENTS for the Categories=================================
var months:Array = events[ie].childNodes[0].childNodes;//get the main <months> nodes in a array
var startX=0;
currentmonth = 1;
startX=115;
var month = events[ie].childNodes[0];
catTextFormat.size = 10;
catTextFormat.color = 0x000000;
catTextFormat.bold = false;
for (im=0; im<months.length; im++) {//iterate through each <month> node
setWidth =72;
var evententry = months[im].childNodes[0].firstChild.nodeValue;
//trace("Entry:"+evententry);
duplicateMovieClip(square, "csquare"+counter, counter);
setProperty("csquare"+counter, _height,setMonthsHeight);
setProperty("csquare"+counter, _x, (startX));
setProperty("csquare"+counter, _y, Number(getProperty("csquare"+(counter-1), _y)));
setProperty("csquare"+counter, _width,setWidth);
if(evententry=="none"){
catTextFormat.color = 0xFFFFFF;
}
else
{
catTextFormat.color = 0x000000;
}
_level0.ScrollPane1.spContentHolder["csquare"+counter].varheading = evententry;
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading.setTextFormat(catTextFormat);
_level0.ScrollPane1.spContentHolder["csquare"+counter].txtheading._x=0;
startX = startX + Number(getProperty("csquare"+counter, _width)+setSpacerX);
counter = counter+1;
currentmonth = currentmonth+1;
}
//currentrow = currentrow+1;
}
}
}
//currentrow = currentrow+1;
};
xml.load("XML/BuildCalendar.xml");
//trace(_global.selCat);
stop();
on (release) {
//var eventToSearch=this._parent.varheading;
trace(this._parent);
trace(this);
var i;
for(i in this._parent.my_data){
trace(i+"="+this._parent.my_data[i]);
}
//}
var xml:XML=new XML(xml_string);
xml.ignoreWhite=true;
xml.load("XML/BuildCalendar.xml")
xml.onLoad = xml_handler;
// executes when xml file has loaded (used as MAIN function)
function xml_handler(success)
{
if (success==true){
//o is the object, that contains attributes, you are interested in.
//For example, here is the name of the event, you are going to select.
//var o:Object={name:"TEST7"};eventToSearch
var o:Object={name:eventToSearch};
var node:XML;
node=first_xml_node(xml, "EV", o);
//trace("Node-->"+node);
//When you select xml node that you need, you should loop through it and read data you need.
temp=node;
var caldata:Array = temp.childNodes;
//trace("XML DATA+++> : "+caldata);
for (icd=0; icd<caldata.length; icd++) {//iterate through each <categorysection> node
//trace("subcat->: "+subcategories[isc].attributes.name);
trace("-----------------------------------------------------------------------------");
myColorObject = new Color(_root.mcdetail.detail_mc.infocolor);
myColorObject.setRGB(0x000000);
trace("Event name: "+caldata[icd].firstChild.childNodes[0].childNodes[0].nodeValue);
_level0.detail_mc.varheading = caldata[icd].firstChild.childNodes[0].childNodes[0].nodeValue;
//_level0.detail_mc.infocolor;
trace("objective name: "+caldata[icd].firstChild.childNodes[1].childNodes[0].nodeValue);
_level0.detail_mc.varobj = caldata[icd].firstChild.childNodes[1].childNodes[0].nodeValue;
trace("desc name: "+caldata[icd].firstChild.childNodes[2].childNodes[0].nodeValue);
_level0.detail_mc.vardesc =caldata[icd].firstChild.childNodes[2].childNodes[0].nodeValue;
trace("details name: "+caldata[icd].firstChild.childNodes[3].childNodes[0].nodeValue);
_level0.detail_mc.vardetail =caldata[icd].firstChild.childNodes[3].childNodes[0].nodeValue;
trace("attendance name: "+caldata[icd].firstChild.childNodes[4].childNodes[0].nodeValue);
_level0.detail_mc.varattend =caldata[icd].firstChild.childNodes[4].childNodes[0].nodeValue;
trace("date name: "+caldata[icd].firstChild.childNodes[5].childNodes[0].nodeValue);
_level0.detail_mc.vardate =caldata[icd].firstChild.childNodes[5].childNodes[0].nodeValue;
trace("venue name: "+caldata[icd].firstChild.childNodes[6].childNodes[0].nodeValue);
_level0.detail_mc.varvenue =caldata[icd].firstChild.childNodes[6].childNodes[0].nodeValue;
trace("notes name: "+caldata[icd].firstChild.childNodes[7].childNodes[0].nodeValue);
_level0.detail_mc.varnotes =caldata[icd].firstChild.childNodes[7].childNodes[0].nodeValue;
trace("hqcontact name: "+caldata[icd].firstChild.childNodes[8].childNodes[0].nodeValue);
_level0.detail_mc.varcontact =caldata[icd].firstChild.childNodes[8].childNodes[0].nodeValue;
trace("-----------------------------------------------------------------------------");
_root.gotoAndPlay(3);
}
}
else{
trace("...error loading xml file");
break;
}
}
function first_xml_node(xml:XML, node_name:String, node_atts:Object):XML{
var i=0, j;
var correct:Boolean;
var temp_node:XML;
while (i<xml.childNodes.length) {
if (xml.childNodes[i] == null) {
trace("correct xml node not found");
//correct xml node not found
return undefined;
}else if (xml.childNodes[i].nodeName == node_name) {
if(node_atts){
//test for correct attributes
//trace("test for correct attributes");
correct=true;
for(j in node_atts){
if(xml.childNodes[i].attributes[j] !=node_atts[j]){
correct=false;
break;
}
}
if(correct){
return xml.childNodes[i];
}else{
if(temp_node=first_xml_node(xml.childNodes[i], node_name, node_atts)){
return temp_node;
}
}
}else{
//attributes are not provided, so we don't need to check them
trace("attributes are not provided, so we don't need to check them");
return xml.childNodes[i];
}
}else{
if(temp_node=first_xml_node(xml.childNodes[i], node_name, node_atts)){
return temp_node;
}
}
i++;
}
return undefined;
}
}
//copy created object to duplicated movieclip
//dupmc=["csquare"+counter];
dupmc=_level0.ScrollPane1.spContentHolder["csquare"+counter];
dupmc.my_data=new Object();
var ii;
for(ii in obj){
dupmc.my_data[ii]=obj[ii];
trace("Data :" +obj[ii]);
}
//After copying object data, add little more debugging:
//trace("instance: "+this+", duplicated obj: "+dupmc);
//trace("instance: "+this+", duplicated obj: ");
//Check the object you've just copied really exists:
trace("copied object: "+dupmc);
var ii=0;
for(ii in dupmc.my_data){
trace(ii+"="+dupmc[ii]);
}
Usage:
//You should have xml already loaded
var xml_string:String="load your xml yourself or just type it here";
var xml:XML=new XML(xml_string);
//o is the object, that contains attributes, you are interested in.
//For example, here is the name of the event, you are going to select.
var o:Object={name:"TEST1"};
var node:XML;
node=first_xml_node(xml, "EV", o);
trace(node);
//When you select xml node that you need, you should loop through it and read data you need.
temp=node;
if(temp=first_xml_node(tem
  if(temp=first_xml_node(tem
    if(temp=first_xml_node(tem
      trace(temp.nodeValue);
    }
  }
}
Open in new window