View Full Version : Calendar datefilter help : (
Robot4Hire
05-15-2003, 03:58 AM
Was wondering if anyone (Cyanblue...) could help me out here.
I am trying to make a calendar using the calendar component. I pass a var into flash using PHP this is as so:
// load dates for games for current month
myDate = new Date();
mm = myDate.getMonth()+1;
yy = myDate.getFullYear();
//add 0 for dates with one digit
if (mm<10) {
mm = "0"+mm;
}
// display only the last 2 digits
myString = yy.toString();
for (i=2;i<myString.length;i++) {
yy = (myString.charAt(2)+myString.charAt(3));
}
gameVars = new LoadVars();
gameVars.month_id = mm+"/"+yy;
gameVars.onLoad = function (success) {
if (success) {
var i = 0;
while (this["day" + i] != undefined) {
trace(this["day" + i]);
++i;
}
}
}
gameVars.sendAndLoad("http://members.lycos.co.uk/robot4hire/monthinfo.php",gameVars,"POST");
I want to make it so that these are the only dates that are selectable. or at leaste highlight them.
Any ideas, here is an example that works using Flash Remoting Componets adn ColdFusion MX . But I am using PHP/MySQL.
CyanBlue I know you can help me as you have so many other times before. I'm hopeing that you can again.
Here is the tut on this calendar but rememebr I want to use PHP that returns this VAR:
Calendar tut (http://www.zdnet.com.au/builder/webdesign/multimedia/story/0,2000040398,20269873,00.htm)
here is what I have for an example that works with some modifying.
The following code sets the date filter to exclude all weekends.
_root.dateFilter = new Object();
_root.dateFilter.isSelectable = function(comp, dt) {
return !(dt.getDay() == 0 || dt.getDay() == 6);
}
_root.theCalendar.setDateFilter(_root.dateFilter);
So if I can tell this to show only dates from the gameVars obj. please tell me how, i have tried so many ways, I can make them disabled and enabled all day long by typeing the dates but I want it to load them using the gameVars obj above.
Robot4Hire
05-16-2003, 03:05 AM
Ok here is a sample FLA.
You might have to right click and choose save as to DL this.
Calendar example (http://www.angelfire.com/geek/robot/cal_example.fla)
If I set the dateFilter to s spacific date then it works. So how can I make it decide what to make selectable or not?
ALso you see how that java crap gets in there? Any sugestions (Besides getting a good host :p )
CyanBlue
05-16-2003, 06:11 AM
Yeah... Get a better host!!! :p
But then, that one is free and I have one myself as well...
Um... I am not sure if I can help you with this or not... So, don't depend on me too much... ;)
First of all... I think it is a good idea to show me the PHP script...
Look here... This is the trace() output of the gameVars that I have edited abit to make this one readable...adpref="></script>&
ord=1898087491&
CC=uk&
mkw=&
day0=10
</pre></xmp></noscript>
<script src="http://ads.tripod.lycos.co.uk/ad/test_frame_size.js"></script>
<script language="javascript">
if (!AD_clientWindowSize()) {
document.write('<NOSC' 'RIPT>');
}
</script>
<script type="text/javascript" src="http://ads.tripod.lycos.co.uk/ad/ad.php?cat=&
onLoad=[type Function]&
month_id=05/03Now, look... I have checked all the places that I think you need from the PHP script in bold... and the one that I have marked as italic looks like you do need that line as well... But you have some unnecessary toll attached at the end... Let me know if I have marked all the things correctly or not...
Now... That italic part... I think you only need 'day0=10', but there is something at the end, right??? If I were you, I'd put something at the end from the PHP script so that you can maybe split it later in Flash... 'day0=10|' would be a good form to print out in PHP... Or, if you could print out two digits from the PHP, you can just slice the whole thing from the third character location when imported into Flash... It's up to you...
You know the names of the variables that are to be returned to Flash, so it will be easy to sort out the unnecessary things in Flash... That way you can get away from the debt of the free hosting... :D
Here... I have edited your onLoad handler so that it reads gameVars.calDate instead of 10... But I am not sure if this is how you want this thing going...gameVars.onLoad = function(success)
{
if (success)
{
trace("=============");
trace("gameVars = " + unescape(gameVars));
trace("=============");
var i = 0;
while (this["day" + i] != undefined())
{
this.calDate = this["day" + i].substr(0, 2);
trace(this["day" + i]);
++i;
}
// I need to load the vars that gameVars.onLoad returns.
_root.dateFilter = new Object();
_root.dateFilter.isSelectable = function(comp, dt)
{
trace("gameVars.calDate = " + gameVars.calDate);
return (dt.getDate() == gameVars.calDate);
// return (dt.getDate() == 10);
};
_root.cal.setDateFilter(_root.dateFilter);
}
};For now, I am limiting that 'day0' for the first two characters assuming that you are sending two digits dates from the PHP code like 03, 15, 21, 31... But you can do whatever you want as long as you are limiting it somehow...
That while loop... You have it loop multiple times depending on the number of you 'day0' variable from the PHP... It will work if you have just one date, but you'll have to have multiples of this.calDate variable if you have multiples... Also, your dataFilter will need some more adjustment according to it...
Also, I have moved that dateFilter routine into the onLoad handler so that the routine will fire only when the data gets loaded... The way you had it set up at the bottom of the code will fire that routine first and the gameVars will try to laod data from the server...
Once, this one is working right, have your PHP pull multiple dates and test it so that you will make the appropriate changes... (Don't forget to show me the PHP script if you need further assistance... ;))
Let me know... ;)
Robot4Hire
05-16-2003, 09:05 PM
Thank you CyanBlue. I think I am missing the part where it filters the date in a while loopand tells the calendar do disaplay the date.
Ok my goal is to get the dates from php/mysql that have events. then only display those in the calendar.
VARS (http://members.lycos.co.uk/robot4hire/monthinfo.php?month_id=05/03)
<?php
$hostname="";
$username="";
$password="";
$dbname="";
$connection = @MYSQL_CONNECT($hostname,$username, $password) OR DIE ("<html>Unable to connect to database. <a href=http://members.lycos.co.uk/robot4hire/>Click here to return.</a><html>");
$db = @mysql_select_db($dbname, $connection) or DIE ("<html>Unable to query to database. <a href=http://members.lycos.co.uk/robot4hire/>Click here to return.</a><html>");
include "functions.php";
$totaldates = "";
$i = 0;
if ($month_id != "") {
list($md,$yd) = explode("/", $month_id);
$query = "select * from sqn_db";
$result = query($query, $connection);
while ($row = mysql_fetch_array($result)) {
$mdate = $row['Date'];
$mid = $row['id'];
list($m,$d,$y) = explode("/", $mdate);
if ($m == $md && $y == $yd) {
$totaldates[] = $d;
#$totaldates2 .= "&day$i=$d";
$i++;
}
}
for ($i = 0; $i < count($totaldates); ++$i) {
#$output .= "&arrayVariable$i=" . urlencode($arrayName[$i]);
$totaldates2 .= "&day$i=" . $totaldates[$i];
}
}
echo $totaldates2;
?>
THis script retunes the date like this
&day0=22&day1=10&day2=19
now flash gets it:
stop();
// set calendar fonts
globalStyleFormat.embedFonts = false;
globalStyleFormat.applyChanges();
cal.setStyleProperty ("textFont", "Arial");
cal.setStyleProperty ("textSize", "10");
// load dates for games for current month
myDate = new Date();
mm = myDate.getMonth()+1;
yy = myDate.getFullYear();
if (mm<10) {
mm = "0"+mm;
}
// display only the last 2 digits of the year yyyy
myString = yy.toString();
for (i=2;i<myString.length;i++) {
yy = (myString.charAt(2)+myString.charAt(3));
}
// Load game stats for the date selected
function getStats() {
_root.mainTxt._visible = false;
theDay = cal.getSelectedItem().getDay();
theNumber = cal.getSelectedItem().getDate();
theMonth = cal.getSelectedItem().getMonth();
theYear = cal.getSelectedItem().getFullYear()
this.theMonth+=1;
tM = theMonth.toString();
tN = theNumber.toString();
dt = tM + tN;
sendVars = new LoadVars();
// add 0 for the months and days that have one digit
if (this.theMonth<=9) {
this.theMonth = "0"+theMonth;
}else{
this.theMonth = theMonth;
}
if (this.theNumber<=9) {
this.theNumber = "0"+theNumber;
}else{
this.theNumber = theNumber;
}
sendVars.id = this.theNumber;
trace (this.theNumber);
sendVars.onLoad = function(success){
// set font format
var c = "<p align=\"left\"><font color =\"#000000\" size = \"16\">";
if(success){
if (this.team!=""){
_root.mainTxt._visible = true;
_root.loadingMC._visible = false;
mainTxt.htmlText = c+"Team: "+
"</font>"+this.team+"<br>"+c+"Time: "+
"</font>"+this.time+"<br>"+c+"Level: "+
"</font>"+this.level+"<br>"+c+"Mode: "+
"</font>"+this.mode+"<br>"+c+"# Players: "
+"</font>"+this.np+"<br>"+c+"KillGoal: "+
"</font>"+this.kg+"<br>"+c+"Time limit: "+
"</font>"+this.tl+"<br>"+c+"Skill: "+
"</font>"+this.skill+"<br>"+c+"Respawn: "+
"</font>"+this.rt+"<br>"+c+"Huds: "+
"</font>"+this.huds+"<br>"+c+"Server: "+
"</font>"+this.server+"<br>"+c+"PowerUps: "+
"</font>"+this.dpu+"<br>"+c+"PPS: "+
"</font>"+this.pps+"<br>"+c+"Setup By: "+
"</font>"+this.sub+"<br>"+c+"Results: "+
"</font>"+this.result;
}else {
_root.mainTxt._visible = true;
_root.loadingMC._visible = false;
mainTxt.htmlText = "<br>There are no games for this day.";
}
}
}
sendVars.sendAndLoad("http://members.lycos.co.uk/robot4hire/gameinfo.php",sendVars,"POST");
}
//////send the month and date to PHP and get back the dates
//////that have events.
gameVars = new LoadVars();
gameVars.month_id = mm+"/"+yy;
gameVars.onLoad = function(success)
{
if (success)
{
trace("=============");
trace("gameVars = " + unescape(gameVars));
trace("=============");
var i = 0;
while (this["day" + i] != undefined())
{
this.calDate[i] = this["day" + i].substr(0, 2);
++i;
trace (this.caldate+i);
}
// I need to load the vars that gameVars.onLoad returns.
_root.dateFilter = new Object();
_root.dateFilter.isSelectable = function(comp, dt)
{
trace("gameVars.calDate = " + gameVars.calDate);
return (dt.getDate() == gameVars.calDate);
// return (dt.getDate() == 10);
};
_root.cal.setDateFilter(_root.dateFilter);
}
};
/*
gameVars = new LoadVars();
gameVars.month_id = mm+"/"+yy;
gameVars.onLoad = function (success) {
if (success) {
var i = 0;
while (this["day" + i] != undefined()) {
this.calDate = this["day"+i];
trace(this["day" + i]);
++i;
}
}
}
*/
gameVars.sendAndLoad("http://members.lycos.co.uk/robot4hire/monthinfo.php",gameVars,"POST");
// I need to load the vars that gameVars.onLoad returns.
/*
_root.dateFilter = new Object();
_root.dateFilter.isSelectable = function(comp, dt) {
return (dt.getDate() == 10);
}
_root.cal.setDateFilter(_root.dateFilter);
*/
CyanBlue
05-17-2003, 04:20 AM
Here... I think this is working now...
_root.dateFilter = new Object();
_root.dateFilter.isSelectable = function(comp, dt)
{
trace("gameVars.calDate = " + gameVars.calDate + "\tgameVars.calDate.length = " + gameVars.calDate.length);
rtnStr = false;
for (i = 0 ; i < gameVars.calDate.length ; i++)
{
this["rtnStr" + i] = dt.getDate() == gameVars.calDate[i];
trace("this[\"rtnStr\" + " + i + "] = " + this["rtnStr" + i]);
rtnStr = rtnStr || this["rtnStr" + i];
}
trace("rtnStr = " + rtnStr);
return rtnStr;
};
_root.cal.setDateFilter(_root.dateFilter);Let me know... ;)
Robot4Hire
05-18-2003, 12:15 AM
Wow thank you CyaBlue, I knew you could do it :) I just wish I understood it better, so I have a question for ya.
Did you learn Actionscript from school? Or did you just read alot a books? I am obviously a noob but am getting a little addicted to it. Any way thanks for all your help. I am not making any money off this or I would share, its just for a game that I play. Descent 3. ever played it? love it. it's another addiction.
There is one other thing though, there is TWO games on the 17th and niether one shows in the calendar. Any suggestions?
CyanBlue
05-18-2003, 12:25 AM
Well... I'm just glad that I was able to pull it out... ;)
I've learned ActionScript at school, I guess... I had known Director for at least 3-4 years before I get my hands laid on Flash, so the starting Flash was real easy for me... I was able to help other classmates right away while I was in the class... ActinScript... That is abit of different story... ActionScript works abit different and same from Director's Lingo in a way... So, I didn't have problem starting on it, but I had some hard time understanding how ActionScript really works... I'll say that you don't get to learn much from the school... You do learn while you browse information like you do in the forum, and you need to spend big time learning it... Time and effort... That's all you need... ;)
Decent 3??? Hm... Do you really want me get addicted to it??? Flash is enough already... I got my life you know... :D
I do not know how you have stored two eents on one date within the database, and how you are loading it via the server side script... I'll need some more details on that to answer your question... ;)
Robot4Hire
05-18-2003, 04:56 AM
Well you certainly good at it. Thank you for all your help. :)
It seems that the more I get into this calendar the harder and more complex that it gets. But if your willing to help me still then here it goes.
well what I have is fields: The ID is unique and autoincrament and I need the date to show in the calendar. The rest are the games stats.
id Date Time Server Team numplayers Level Mode PPS Skill RepawnTime KillGoal Timelimit huds disallowpu results setupby
Then you have the PHP and Actionscript.
I was thinking that I should make a function for the datefilter so that when I click on the next month it will call it so it can load the next months date . I have added some for June just to start testing that out. but any advice that you will give I would appreciate.
CyanBlue
05-18-2003, 09:57 AM
Well... This is what I think...
You are returning &day0=22&day1=10&day2=19 back to Flash... and Flash utilizes those data...
If you have multiple events for the same day, You'd have to return the combined data back to Flash from the PHP script, and have Flash display it on top of another, I mean the first one on top and the second one at the end of the first one...
That way you don't have to worry too much about how to split two events and such...
BTW, I see that multiple months working just fine now... You just need to tidy up the displaying part and I think you are done with what you wanted to accomplish... Good job... :)
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.