View Full Version : Flash/AS3 XML Event Calendar
ghostir
February 25th, 2009, 02:05 PM
I am creating an XML-driven events calendar. What I have so far may be viewed at www.harlemedc.biz/activities.htm (http://www.harlemedc.biz/activities.htm).
Within the activities XML file are twelve “month” nodes, within which there are up to three “item” nodes. Each "item" may contain one “event” string (displayed, slightly overlaying the 3-character month abbreviation) and one “info” string, describing the "event" in more detail.
What I am trying to do is display the info for an item whenever a displayed "event" is clicked. I’ve determined that I can detect the click using a TextEvent.LINK listener. Still cannot figure how to retrieve the proper "info" upon clicking its related "event", in a simple manner.
Does this make sense to anyone? I can provide more details.
Thanks!
MurtenSaerbi
February 25th, 2009, 04:05 PM
Mmm.. This definately makes sense and pretty much depends on how good you are in actionscript. I would create a container (a MovieClip that contains a textfield, for instance) and fill those up. That way you can attach an EventListener to the movieclip. On Click (simple event listener) I would dispatch a custom event which holds the node information. That way you can easily retrieve the "info string" and show it any way you want it.
You could ofcourse always create an array which holds the events and one with the info (or even a multidimensional one which holds both) and then retrieve the info by using the number (infoArray[2] and eventsArray[2] will both be about the same event).
creatify
February 25th, 2009, 06:21 PM
I agree with MurtenSaerbi, many ways to skin a cat... this is the common issue of a number of objects that when sending out an event need to some how find the "matching item" - in your case, the additional information that is in the xml.
One "easier" way is the following. Granted, you have to have full control of the XML (asking a client to do this would be risky) and you have to be organized, but it's an easier concept if you don't want to create a "listItemObject" with custom properties that you associate each event text too. If you have more AS experience, I'd recommend against this, but usually this is a easy way to start associating how the pairing of items works:
If you're going to use LINK, then I'd just add the a href links into your XML. See here: http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/TextEvent.html#LINK
where they're using
<a href=\"event:os\">
you could simply use
<a href=\"event:jan_0\">
<a href=\"event:jan_1\">
<a href=\"event:feb_2\">asdfasdfasdf</a>
The numbers would just correspond to the exact node order in the xml doc.
then in your link handler:
function linkHandler(e:TextEvent):void {
//need to separate the number from the month
var parts:Array = e.text.split("_");
trace(parts);
//So, you have "jan","0"
//or say "feb","3"
// then you find the appropriate month node and use the number to find the index of the corresponding item:
// I haven't tested this code, but think it's correct
trace(yourMainLoadedXML.month.(@id==parts[0]).item[int(parts[1])].info.toString());
// the problems with this method of retrieving data are
// you have to be certain that the jan_0 is input correctly in the xml
// within the xml, these won't work:
/*
jann_0
jan_A
jan__2
*/
/*
That said, creating custom objects for your event list items, you can store the data within properties of the objects themselves,
or you can loop through the xml when creating the objects and then create some type of binding id that each cell uses to find the content when clicked. And
yes, that would be setting up sprites or movieclips, then adding the textField to them, so like mentioned above, you'd stop using LINK and use MOUSE_DOWN or something
on the container.
*/
}
ghostir
February 26th, 2009, 08:13 AM
Thank you both!
Of course, it always depends upon one's skill level...I have been Actionscripting for a few years, but am just getting into AS3 and don't wish to turn back.
Prior to posting this query, my initial thoughts ran concurrent with yours regarding the "container" approach, and will probably pursue this. Ultimately, it should be easy for the client, not me! As you probably noticed, this is a volunteer effort, and it must be maintainable by the client, as much as possible. They can deal with a simply-formatted XML file.
Guess I was wanting to assure myself there was not some more obvious means, of which I am still ignorant.
Thanks again!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.