all groups > flash actionscript > november 2007 >
You're in the

flash actionscript

group:

Looking for Calendar help or tutorial


Looking for Calendar help or tutorial flashForum
2/14/2006 12:40:15 AM
flash actionscript:
The dateChooser component in Flash is cool, but upon further investigation
there appears to be a lack of useful information. I want to be able to click a
date and have a text box, or several text boxes populate with data of my
choosing. Where can I find information on this? I've seen the Macromedia
documentation about the fake airline etc, nothing really useful.
Re: Looking for Calendar help or tutorial NSurveyor
2/14/2006 1:43:03 AM
It's all right there in the Help panel. When I do something like this, I try to
find what I need to make this work. For instance, when should you populate the
textboxes? Why, when you select something in the DateChooser, which immediately
tells me I need to find the right event for the component. Just open up that AS
reference on the side of the Actions Panel, go to Components > DateChooser >
Events. And look at that! The first event is called 'change'. Is that what we
want? Just right click it, and hit view help. And there it is... even some
sample code. Personally, when I use components, I make the component itself the
listener because I rarely ever have more than one listener anyways. So, let's
say we have a DataChooser with instance name, myDC. We could place the
following code for the change handler

myDC.change = function(){
trace("i've changed!");
}
myDC.addEventListener('change',myDC);

Test it. When you select a date, some text is traced. But now we need some
meaning. Ok, so how do we get the selected date? Just look in the AS reference
on the side again, but this time under the Properties of the DataChooser. Just
skimming through them, we see selectedDate, which sounds like exactly what we
want. You can right click and hit View Help to read more about it. Now let's
apply this newfound knowledge:

myDC.change = function(){
trace(this.selectedDate);
}
myDC.addEventListener('change',myDC);

Now, how do we get something to happen if the selected date is a specific one?
You could convert the date to a string, and do some easy logic. From there, the
possibilities are endless!

myDC.change = function(){
var d = this.selectedDate;
var d_str = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear();
switch(d_str){
case "2/13/2006":
trace('why that was today if today is still 2/13');
break;
case "2/14/2006":
trace('howdy tomorrow!');
break;
default:
trace("no event today...");
break;
}
}
myDC.addEventListener('change',myDC);

and inside those conditionals, you can set the contents of a textfield with
something as simple as:

my_txt.text = "hello mister, how are you today?";
Re: Looking for Calendar help or tutorial flashForum
2/14/2006 7:57:20 PM
I just get errors when I try to paste that code. I just need to study AS over
and over until it makes sense - it's not sticking at all. But at least you
showed me some documentation - funny that it was all right there the whole time
- thanks for the reply.

Why should something so common be so hard? Event calendars seem like
something that should be point and click.
Re: Looking for Calendar help or tutorial NSurveyor
2/14/2006 8:31:35 PM
Re: Looking for Calendar help or tutorial flashForum
2/15/2006 10:25:44 PM
Ha - I placed it not on the keyframe, but on the movie itself. When I placed
it on the keyframe it worked. Pretty cool. Wow - now I can just create a
bunch of text fields, give them instance names and put them after "case".
You're awesome. Wanna do some freelance work for me :)
Re: Looking for Calendar help or tutorial flashForum
2/15/2006 10:30:29 PM
But you know, it's not very practical if you have several events on every day
for 10 years - as is the case. How would you go about making this practical in
that regard. Better yet, and I'll pay you for it if I have to - can you make
it so an end user can access a html page and make the changes themself without
touching the flash file?
Re: Looking for Calendar help or tutorial NSurveyor
2/15/2006 11:00:43 PM
Yes you can. I guess the most practical thing to use, is an xml file. I was
merely demonstrating that it isn't too hard to whip up. For this code, you
will need to have a calandar with instance name, myDC and three textfields:
name_txt, desc_txt, and info_txt. In this code, these names are equivalent to
the names used in the xml file. For example, if you had: <food>Apples</food> in
the xml, you would have food_txt to show this value.

SAVE THE FOLLOWING AS events.xml IN THE SAME DIRECTORY AS YOUR SWF:

<events>
<event date="2/14/2006">
<name>Valentine's Day!</name>
<desc>I can't believe I forgot this day was a holiday!</desc>
<info>This holiday is associated with hearts and cupid</info>
</event>

<event date="2/15/2006">
<name>Blah Day</name>
<desc>The day of blah!</desc>
<info>this holiday is fake, btw</info>
</event>

<event date="2/16/2006">
<name>Tomorrow</name>
<desc>if today is still 2/15</desc>
<info>hehhehehehhe</info>
</event>
</events>

THIS IS THE CODE TO GO ON THE FRAME IN FLASH:

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(s){
if(s){
eventArray = [];
var children = this.firstChild.childNodes;
for(var c=0;c<children.length;c++){
var cEvent = children[c];
var cObj = {};
for(var d=0;d<cEvent.childNodes.length;d++){
var node = cEvent.childNodes[d];
var field = node.nodeName;
var value = node.firstChild.nodeValue;
cObj[field] = value;
}
eventArray[cEvent.attributes.date] = cObj;
}
myDC.enabled = true;
}else{
trace('Error loading file!');
}
}
myXML.load('events.xml');
myDC.enabled = false;
myDC.change = function() {
var d = this.selectedDate;
var d_str = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear();
var cEvent = eventArray[d_str];
name_txt.text = '';
desc_txt.text = '';
info_txt.text = '';
if(cEvent){
for(var obj in cEvent){
this._parent[obj+'_txt'].text = cEvent[obj];
}
}
};
myDC.addEventListener('change', myDC);
Re: Looking for Calendar help or tutorial flashForum
2/15/2006 11:22:37 PM
Re: Looking for Calendar help or tutorial NSurveyor
2/15/2006 11:57:08 PM
You're welcome.

Re: Looking for Calendar help or tutorial flashForum
2/17/2006 12:54:52 PM
Re: Looking for Calendar help or tutorial Mark.P.
5/14/2006 12:49:50 PM
NSurveyor -

I see this is a few months old but hope it's not too late to jump on and get
some help as well. Everything I see is perfect for what I need, but the one
thing I can't figure out, and doesn't seem to be part of the code, is how do
you highlight the days that have events attached to them? If you have all
kinds of dates scattered you don't want the user seaching for them so I'd think
there should be a way to hightlight those dates, but I can't find it. I see how
to hightlight one or a range of dates, but that's it.

Ideas?
Re: Looking for Calendar help or tutorial NSurveyor
5/14/2006 7:48:00 PM
Try this code: (not the last 4 lines)

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(s) {
if (s) {
eventArray = [];
keepDays = [];
var children = this.firstChild.childNodes;
for (var c = 0; c<children.length; c++) {
var cEvent = children[c];
var cObj = {};
for (var d = 0; d<cEvent.childNodes.length; d++) {
var node = cEvent.childNodes[d];
var field = node.nodeName;
var value = node.firstChild.nodeValue;
cObj[field] = value;
}
eventArray[cEvent.attributes.date] = cObj;
var dP = cEvent.attributes.date.split('/');
keepDays.push(new Date(Number(dP[2]), Number(dP[0])-1, Number(dP[1])));
}
myDC.enabled = true;
myDC.scroll();
} else {
trace('Error loading file!');
}
};
myXML.load('events.xml');
myDC.enabled = false;
myDC.change = function() {
var d = this.selectedDate;
var d_str = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear();
var cEvent = eventArray[d_str];
name_txt.text = '';
desc_txt.text = '';
info_txt.text = '';
if (cEvent) {
for (var obj in cEvent) {
this._parent[obj+'_txt'].text = cEvent[obj];
}
}
};
myDC.scroll = function(eObj) {
var dR = [];
var lD = new Date(this.displayedYear, this.displayedMonth+1, 0).getDate();
for (d=1; d<=lD; d++) {
var nD = new Date(this.displayedYear, this.displayedMonth, d);
dR.push(nD);
}
for (var k = 0; k<keepDays.length; k++) {
if (keepDays[k].getFullYear() == this.displayedYear &&
keepDays[k].getMonth() == this.displayedMonth) {
dR[keepDays[k].getDate()-1] = null;
}
}
this.disabledRanges = dR;
};
myDC.addEventListener('scroll', myDC);
myDC.addEventListener('change', myDC);
myDC.setStyle('disabledColor', '0xFF0000');
_global.styles.CalendarLayout.setStyle("color", "0x0000FF");
_global.styles.HeaderDateText.setStyle("color", "0x00FF00");
_global.styles.WeekDayStyle.setStyle("color", "0xFF00FF");
Re: Looking for Calendar help or tutorial forumnotifier
5/14/2006 7:48:03 PM
Try this code: (not the last 4 lines)

myXML = new XML();
myXML.ignoreWhite = true;
myXML.onLoad = function(s) {
if (s) {
eventArray = [];
keepDays = [];
var children = this.firstChild.childNodes;
for (var c = 0; c<children.length; c++) {
var cEvent = children[c];
var cObj = {};
for (var d = 0; d<cEvent.childNodes.length; d++) {
var node = cEvent.childNodes[d];
var field = node.nodeName;
var value = node.firstChild.nodeValue;
cObj[field] = value;
}
eventArray[cEvent.attributes.date] = cObj;
var dP = cEvent.attributes.date.split('/');
keepDays.push(new Date(Number(dP[2]), Number(dP[0])-1, Number(dP[1])));
}
myDC.enabled = true;
myDC.scroll();
} else {
trace('Error loading file!');
}
};
myXML.load('events.xml');
myDC.enabled = false;
myDC.change = function() {
var d = this.selectedDate;
var d_str = (d.getMonth()+1)+'/'+d.getDate()+'/'+d.getFullYear();
var cEvent = eventArray[d_str];
name_txt.text = '';
desc_txt.text = '';
info_txt.text = '';
if (cEvent) {
for (var obj in cEvent) {
this._parent[obj+'_txt'].text = cEvent[obj];
}
}
};
myDC.scroll = function(eObj) {
var dR = [];
var lD = new Date(this.displayedYear, this.displayedMonth+1, 0).getDate();
for (d=1; d<=lD; d++) {
var nD = new Date(this.displayedYear, this.displayedMonth, d);
dR.push(nD);
}
for (var k = 0; k<keepDays.length; k++) {
if (keepDays[k].getFullYear() == this.displayedYear &&
keepDays[k].getMonth() == this.displayedMonth) {
dR[keepDays[k].getDate()-1] = null;
}
}
this.disabledRanges = dR;
};
myDC.addEventListener('scroll', myDC);
myDC.addEventListener('change', myDC);
myDC.setStyle('disabledColor', '0xFF0000');
_global.styles.CalendarLayout.setStyle("color", "0x0000FF");
_global.styles.HeaderDateText.setStyle("color", "0x00FF00");
_global.styles.WeekDayStyle.setStyle("color", "0xFF00FF");
Re: Looking for Calendar help or tutorial Mark.P.
5/15/2006 12:47:02 AM
wow, absolutely amazing! That's exactly what I was hoping for! Thank you so much the fast reply.

Re: Looking for Calendar help or tutorial NSurveyor
5/15/2006 1:11:29 AM
RE: Looking for Calendar help or tutorial Saravanan
11/8/2007 12:55:54 AM
Can you please give me a solution for how to make a dates in a calendar for whichever year it may be... When the press on Jan 1 st it have to get some movie clip or some action script like

GotoAndPlay (25);

something so can you please give a solution...

I am using same Date Chooser Default component in Flash CS3

From http://www.developmentnow.com/g/69_2006_2_0_0_696818/Looking-for-Calendar-help-or-tutorial.htm

Posted via DevelopmentNow.com Groups
AddThis Social Bookmark Button