Flash has a Date object, that can give you the date and time, but it gives you the date and time that is on the users computer.
e.g.
var dt:Date = new Date();
trace(dt);
This will trace out whatever time the user's computer is set to, whether it is 5mins slow, or 10 years fast.
If this date/time is being used for some kind of authentication i.e. to see if the deadline is past, then you should load the time from the server.
var ld:LoadVars = new LoadVars();
ld.onLoad = function(succ:Boolean) {
dt_txt.text = this.servertime;
}
ld.sendAndLoad('servertime.php',ld,'POST');
On the servertime.php file:
$today = date('YmdHis');
echo "&servertime=$today";
?>
(Sometimes I have issues with the data being echoed out, try removing the ampersand from the front, or not.)
The reason why I use the date('YmdHis') is because it gives you a number that is perfect for sorting, and a recognised datetime stamp for mysql, if you ever need it.
4.30pm (and 22 seconds), 5/11/2012 = 20121105163022
If you need to sort the dates, you can do a numeric sort. If you want to check if something happened before Jun 2012, you look to see if the number is smaller than 20120600000000, and so on.
A diary about programming problems - to help me more easily learn from (and Google) past mistakes.
Thursday, 12 April 2012
Tuesday, 10 April 2012
How to make a div scrollable
<style type="text/css">
div.scroller
{
overflow: scroll;
width:300px;
height:500px;
}
</style>
...
<div id="scroller"></div>
The scroller property is controlled via css. You won't see the scroll bars unless their is a width and height to your div.
How to use javascript to change an element's attributes
document.getElementById('id').setAttribute("style","position:absolute;left:10px");
This method is useful if you have a lot of properties to add, but it can overwrite the other style attributes that you may have already set.
An alternative method is:
document.getElementById('id').style.width = "500px";
Sunday, 8 April 2012
Javascript: Rewrite element content
How to change the content of an element...?
In the head tag:
In the body tag:
In the head tag:
<script type="text/javascript">
function giveWidth(e) {
document.getElementById('wid').innerHTML = window.innerWidth;
}
</script>
In the body tag:
<p>Window width <a href="" onclick="giveWidth(event);return false">is</a> <span id="wid">500</span> pixels.<p>
The return false makes sure that the browser doesn't try to open a new window when you click on the link.
Tuesday, 27 March 2012
How to Make Your swf Resize to Fit The Browser Window Automatically
If you want your swf to be as big as it can be in the browser window, and to resize automatically fit the user resizes the browser window:
Change the width and height values to 100%, and the scale to "default".
e.g.
Obviously, if you have the script included, then you will need to change the values there too.
By the same token, you could set the swf to fill up most, but not all of the screen, by setting width and height to 80%, for example.
Change the width and height values to 100%, and the scale to "default".
e.g.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="100%" height="100%" id="oxphos" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="allowFullScreen" value="false" />
<param name="movie" value="oxphos.swf" />
<param name="loop" value="false" />
<param name="menu" value="false" />
<param name="quality" value="high" />
<param name="scale" value="default" />
<param name="bgcolor" value="#ffffff" />
<embed src="oxphos.swf" loop="false" menu="false" quality="high" scale="default" bgcolor="#ffffff" width="100%" height="100%" name="oxphos" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />
</object>
Obviously, if you have the script included, then you will need to change the values there too.
By the same token, you could set the swf to fill up most, but not all of the screen, by setting width and height to 80%, for example.
Thursday, 22 March 2012
How to Create a MySQL Database if it Doesn't Exist - Very Easily
This is so easy I almost don't believe it, except I've tested it and it works.
$create = mysql_query("CREATE DATABASE IF NOT EXISTS databasename");
Crazy easy, no?
$create = mysql_query("CREATE DATABASE IF NOT EXISTS databasename");
Crazy easy, no?
Sunday, 11 March 2012
Mariam's clock
Note to teacher: Mariam did this herself, she is quite familiar with Flash by now, though she did need some help. When she needed help, I told how to do things, so she did them herself. From this experience, one of the things I could see her learning was that the numbers have to be positioned correctly, or a 'quarter' isn't really a quarter. So she repositioned some numbers in the last page.
Subscribe to:
Posts (Atom)