A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: event calendar with xml

  1. #1
    Junior Member
    Join Date
    Sep 2008
    Posts
    6

    event calendar with xml

    hi,
    i found many posts about xml and event calendars, but nothing that resolves my problem (maybe that`s why I`m a noob....)

    I would make a simply kind of calendar with concert dates, like

    10.06.2008 Gasomer Vienna
    21.12.2008 Backstage Munich
    02.01.2009 Alcatraz Milano
    (date, location, place)

    I would realize this with a external XMLFile, so that I can simply change or add other dates.
    Also I want display passed dates in an other style, like

    10.06.2008 Gasomer Vienna --> passed dates
    21.12.2008 Backstage Munich --> actual date
    02.01.2009 Alcatraz Milano --> next dates
    12.02.2009 Club Vaudeville Bregenz --> next dates

    maybe someone has some template or solttion for this

    thanks a lot,
    Chris

    ps: maybe it`s the wrong forum and I should post this in the Flash Newbie Forum.... sorry
    Last edited by schtoffl; 09-04-2008 at 06:14 AM.

  2. #2
    :
    Join Date
    Dec 2002
    Posts
    3,518

    Maybe you can adapt this to what you are trying to do...

    XML file, called 'info.xml'
    Code:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <events>
    	<item date="10.06.2008" locale="Gasomer" place="Vienna" />
    	<item date="21.12.2008" locale="Backstage" place="Munich" />
    	<item date="02.01.2009" locale="Alcatraz" place="Milano" />
    	<item date="12.02.2009" locale="Club Vaudeville" place="Bregenz" />
    	<item date="05.09.2008" locale="some" place="thing" />
    </events>
    AS2 code on main timeline...
    Code:
    stop();
    var newDate = new Date();
    var currentTime = newDate.getTime();
    var rangeTime = newDate.setDate(newDate.getDate() + 7);
    var infoArray = new Array();
    //
    var myXML:XML = new XML();
    myXML.ignoreWhite = true;
    myXML.load("info.xml");
    myXML.onLoad = function(success) {
    	if (success) {
    		var myX = myXML.firstChild.childNodes;
    		var totalNum = myXML.firstChild.childNodes.length;
    		for (var i = 0; i < totalNum; i++) {
    			var d = (myXML.firstChild.childNodes[i].attributes.date);
    			var l = (myXML.firstChild.childNodes[i].attributes.locale);
    			var p = (myXML.firstChild.childNodes[i].attributes.place);
    			var dd = d.split(".");
    			var infoDate = new Date(dd[2], dd[1]-1, dd[0]);
    			var t = infoDate.getTime();
    			infoArray.push({D:d, L:l, P:p, T:t});
    		}
    		infoArray.sortOn("T", 16);
    		showInfo();
    	}
    };
    function showInfo() {
    	this.createTextField("my_txt", 1, 100, 100, 300, 500);
    	my_txt.multiline = true;
    	my_txt.wordWrap = true;
    	my_txt.html = true;
    	for (j = 0; j < infoArray.length; j++) {
    		if (infoArray[j].T < currentTime) {
    			begSpan = "<FONT COLOR='#CCCCCC'>";
    		} else if (infoArray[j].T >= currentTime && infoArray[j].T <= rangeTime) {
    			begSpan = "<FONT SIZE='16' COLOR='#FF0000'>";
    		} else {
    			begSpan = "<FONT COLOR='#000000'>";
    		}
    		my_txt.htmlText += begSpan + infoArray[j].D + " " + infoArray[j].L + " " + infoArray[j].P + "</FONT>" + newline;
    	}
    }

  3. #3
    Junior Member
    Join Date
    Sep 2008
    Posts
    6
    thanks a lot! I will try to adapt it!

  4. #4
    Junior Member
    Join Date
    Sep 2008
    Posts
    6
    hi!
    I tried to adapt it, and it works, but there are some things that I don`t understand:
    var rangeTime = newDate.setDate(newDate.getDate() + 7);
    this defines the timerange which marks the dates red. But i don`t want to mark more dates red but just one. Only next upcoming date should be red. And if the event is on the same that is today (for example if today is the 1.9.08, the event "1.9.08 location place" should be red until the day is over)

    thanks again,

  5. #5
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    stop();
    var newDate = new Date();
    newDate = new Date(newDate.getFullYear(), newDate.getMonth(), newDate.getDate());
    var currentTime = newDate.getTime();
    var infoArray = new Array();
    //
    var myXML:XML = new XML();
    myXML.ignoreWhite = true;
    myXML.load("info.xml");
    myXML.onLoad = function(success) {
    	if (success) {
    		var myX = myXML.firstChild.childNodes;
    		var totalNum = myXML.firstChild.childNodes.length;
    		for (var i = 0; i < totalNum; i++) {
    			var d = (myXML.firstChild.childNodes[i].attributes.date);
    			var l = (myXML.firstChild.childNodes[i].attributes.locale);
    			var p = (myXML.firstChild.childNodes[i].attributes.place);
    			var dd = d.split(".");
    			var infoDate = new Date(dd[2], dd[1] - 1, dd[0]);
    			var t = infoDate.getTime();
    			infoArray.push({D:d, L:l, P:p, T:t});
    		}
    		infoArray.sortOn("T", 16);
    		showInfo();
    	}
    };
    function showInfo() {
    	this.createTextField("my_txt", 1, 100, 100, 300, 500);
    	my_txt.multiline = true;
    	my_txt.wordWrap = true;
    	my_txt.html = true;
    	var firstOne = true;
    	for (j = 0; j < infoArray.length; j++) {
    		if (infoArray[j].T < currentTime) {
    			begSpan = "<FONT COLOR='#CCCCCC'>";
    		} else if (infoArray[j].T >= currentTime && firstOne) {
    			begSpan = "<FONT SIZE='16' COLOR='#FF0000'>";
    			firstOne = false;
    		} else {
    			begSpan = "<FONT COLOR='#000000'>";
    		}
    		my_txt.htmlText += begSpan + infoArray[j].D + " " + infoArray[j].L + " " + infoArray[j].P + "</FONT>" + newline;
    	}
    }

  6. #6
    Junior Member
    Join Date
    Sep 2008
    Posts
    6

    Thumbs up

    thanks, it works perfectly!!
    I`m really pleased with this solution.

    If you are not to busy, I have a last question... Otherwise, thanks a lot! :-)


    Example: I have 10 passed dates, and 10 forthcoming dates
    If I will show 5 dates only, how can I handle it, that the next/current date (and four that will follow) will be shown?


    -> if i <= 5 ->> show all dates

    -> if i > 5 --> show the next 5 dates (=don`t display the passed shows, only the first 5 of the forthcoming dates)


    and the last: I will show 5 dates. If there are only 3, I get a "undefined" for 2 dates. How can I solve this?



    Chris

  7. #7
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    function showInfo() {
    	this.createTextField("my_txt", 1, 100, 100, 300, 500);
    	my_txt.multiline = true;
    	my_txt.wordWrap = true;
    	my_txt.html = true;
    	var firstOne = true;
    	var count = 0;
    	for (j = 0; j < infoArray.length; j++) {
    		if (infoArray[j].T >= currentTime) {
    			if (infoArray[j].T >= currentTime && firstOne) {
    				begSpan = "<FONT SIZE='16' COLOR='#FF0000'>";
    				firstOne = false;
    			} else {
    				begSpan = "<FONT COLOR='#000000'>";
    			}
    			my_txt.htmlText += begSpan + infoArray[j].D + " " + infoArray[j].L + " " + infoArray[j].P + "</FONT>" + newline;
    			count++;
    			if (count == 5) {
    				break;
    			}
    		}
    	}
    }

  8. #8
    Junior Member
    Join Date
    Sep 2008
    Posts
    6
    the script works also perfectly.

    but (I hope this is really the last question), but how can i combine the two scripts?


    this script shows all dates (max 17):
    function showInfo() {
    this.createTextField("my_txt",1,50,87,800,800);
    my_txt.multiline = true;
    my_txt.wordWrap = true;
    my_txt.html = true;
    var count = 0;
    var firstOne = true;

    for (j=0; j<infoArray.length; j++) {
    if (infoArray[j].T<currentTime) {
    begSpan = "<textformat leading='4'><FONT FACE='Verdana' SIZE='11' COLOR='#666666' LETTERSPACING='1'>";
    } else if (infoArray[j].T>=currentTime && firstOne) {
    begSpan = "<textformat leading='4'><FONT FACE='Verdana' SIZE='11' COLOR='#FF9900' LETTERSPACING='1'>";
    firstOne = false;
    } else {
    begSpan = "<textformat leading='4'><FONT FACE='Verdana' SIZE='11' COLOR='#ffffff' LETTERSPACING='1'>";
    }
    my_txt.htmlText += begSpan+infoArray[j].D+" "+infoArray[j].L+" "+infoArray[j].P+"</FONT></b></textformat>"+newline;
    count++;
    if (count == 17) {
    break;
    }
    }
    }


    and this script shows 5 dates from the current date:
    function showInfo() {
    this.createTextField("my_txt",1,50,87,800,800);
    my_txt.multiline = true;
    my_txt.wordWrap = true;
    my_txt.html = true;
    var firstOne = true;
    var count = 0;

    for (j = 0; j < infoArray.length; j++) {
    if (infoArray[j].T >= currentTime) {
    if (infoArray[j].T >= currentTime && firstOne) {
    begSpan = "<textformat leading='4'><FONT FACE='Verdana' SIZE='11' COLOR='#FF9900' LETTERSPACING='1'>";
    firstOne = false;
    } else {
    begSpan = "<textformat leading='4'><FONT FACE='Verdana' SIZE='11' COLOR='#ffffff' LETTERSPACING='1'>";
    }
    my_txt.htmlText += begSpan+infoArray[j].D+" "+infoArray[j].L+" "+infoArray[j].P+"</FONT></b></textformat>"+newline;
    count++;
    if (count == 5) {
    break;
    }
    }
    }
    }


    This two scripts works perfectly on its own, but I want to combine all together:

    If there are 10 or less dates (COMPLETE NUMBER OF DATES-> passed and forthcoming) I will show ALL DATES (passed and forthcoming)

    If there are 10 dates or more dates (count the CURRENT AND FORTHCOMING) I will show only the CURRENT DATE and nine that will follow.

    If there are less than 10 dates (count the CURRENT AND FORTHCOMING) I will show the CURRENT DATE and THE FORTHCOMING, and attach the PASSED DATES (in chronological order, so that the passed dates stands over the current and forthcoming) until the number of the limit (10) is reached.


    example:

    10 or less dates (complete number of dates):

    10.05.2008 location1 place
    20.06.2008 location2 place

    22.12.2008 location3 place
    01.01.2009 location4 place




    10 or more dates (count the CURRENT AND FORTHCOMING):

    xmlfile with 20 dates-> 5 passed and 15 forthcoming
    Output:
    22.12.2008 location3 place
    10.01.2009 location4 place
    12.01.2009 location5 place
    14.01.2009 location6 place
    16.01.2009 location7 place
    18.01.2009 location8 place
    20.01.2009 location9 place
    22.01.2009 location10 place
    24.01.2009 location11 place
    26.01.2009 location12 place



    less than 10 dates (count the CURRENT AND FORTHCOMING):

    xmlfile with 18 dates-> 12 passed and 6 forthcoming
    Output:
    02.09.2008 location4 place
    03.09.2008 location4 place
    04.09.2008 location4 place
    05.09.2008 location4 place

    22.12.2008 location3 place
    10.01.2009 location4 place
    12.01.2009 location5 place
    14.01.2009 location6 place
    16.01.2009 location7 place
    18.01.2009 location8 place

  9. #9
    :
    Join Date
    Dec 2002
    Posts
    3,518
    Code:
    myXML.onLoad = function(success) {
    	if (success) {
    		var myX = myXML.firstChild.childNodes;
    		var totalNum = myXML.firstChild.childNodes.length;
    		for (var i = 0; i < totalNum; i++) {
    			var d = (myXML.firstChild.childNodes[i].attributes.date);
    			var l = (myXML.firstChild.childNodes[i].attributes.locale);
    			var p = (myXML.firstChild.childNodes[i].attributes.place);
    			var dd = d.split(".");
    			var infoDate = new Date(dd[2], dd[1] - 1, dd[0]);
    			var t = infoDate.getTime();
    			infoArray.push({D:d, L:l, P:p, T:t});
    		}
    		infoArray.sortOn("T", 16);
    		var isAt = 0;
    		for (j = 0; j < infoArray.length; j++) {
    			if (infoArray[j].T >= currentTime) {
    				isAt = j;
    				break;
    			}
    		}
    		showInfo(isAt);
    	}
    };
    function showInfo(isAt) {
    	this.createTextField("my_txt", 1, 50, 87, 800, 800);
    	my_txt.multiline = true;
    	my_txt.wordWrap = true;
    	my_txt.html = true;
    	var firstOne = true;
    	var sVal = 0;
    	var eVal = infoArray.length;
    	if (eVal > 10) {
    		if (eVal - isAt > 10) {
    			sVal = isAt;
    			eVal = isAt + 10;
    		} else {
    			sVal = eVal - 10;
    		}
    	}
    	for (j = sVal; j < eVal; j++) {
    		if (infoArray[j].T < currentTime) {
    			begSpan = "<FONT FACE='Verdana' SIZE='11' COLOR='#666666' LETTERSPACING='1'>";
    		} else if (infoArray[j].T >= currentTime && firstOne) {
    			begSpan = "<FONT FACE='Verdana' SIZE='11' COLOR='#ff9900' LETTERSPACING='1'>";
    			firstOne = false;
    		} else {
    			begSpan = "<FONT FACE='Verdana' SIZE='11' COLOR='#ffffff' LETTERSPACING='1'>";
    		}
    		my_txt.htmlText += "<textformat leading='4'>" + begSpan + infoArray[j].D + " " + infoArray[j].L + " " + infoArray[j].P + "</FONT></textformat>" + newline;
    	}
    }

  10. #10
    Junior Member
    Join Date
    Sep 2008
    Posts
    6

    resolved

    thank you very much for your patience!!!

    Chris

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center