| S | M | T | W | T | F | S |
| 1 | 2 | |||||
| 3 | 4 | 5 | 6 | 7 | 8 | 9 |
| 10 | 11 | 12 | 13 | 14 | 15 | 16 |
| 17 | 18 | 19 | 20 | 21 | 22 | 23 |
| 24 | 25 | 26 | 27 | 28 | 29 | 30 |
I know I’m a little late to the party on this one but I finally cracked Flash Classes last weekend - yay!
To be honest there wasn’t really a whole lot to crack, just the definitions of private and public functions.
Essentially a public function will execute when the class is initialised, and a private function will wait to be called, and that’s all there is to it .
Try this out:
In a text editor create a file and name it TestClass.as
Type the following:
class TestClass{
public function foo(){
trace(“Hello from Foo”);
}
private function baa(){
trace(“Hello from Baa”);
}
}
Now create a new Flash document and save it in the same folder as TestClass.as
On frame one (or any other) type:
var myTestClass = new TestClass();
now publish your movie and you should get the output “Hello from Foo”
If you now add the following line:
myTestClass.baa();
publish your movie and you should get the output “Hello from Foo”, “Hello from Baa”
Yes, it really is that easy.

If you’d like to jazz up the stock Flash List component - like the one I made in this tutorial, you only need a few extra lines of code. It’s all fairly self explanatory, just make sure the instance name ‘aList’ matches the name of your list.
aList.setStyle("fontFamily", "impact");
aList.setStyle("fontSize", 14);
aList.setStyle("color", 0xD20000);
aList.setStyle("rollOverColor", "white");
aList.setStyle("backgroundColor", 0xF1D951);
aList.setStyle("selectionColor", "black");
aList.setStyle("textSelectedColor", "white");
The Sloomedia Database
Rather than spend ages getting the Easypeasy database working I decided to look for a better source. After a few Googles I came up with the Sloomedia database, this returns an accurate latitude & longitude from every outcode, making it ideal for the postcode widget.
I’ve adapted my initial php script to put together a working demo. This shows the initial lookup stage. From here you’ll be prompted to place a marker on the postcode location and complete an email form to validate the entry.
There’s no built in validation so remember to put the space into the middle of the postcode as in: “W1W 8SY”
Give the demo a try – it’s fun.
Reference:
http://www.sloomedia.com/php_postcode_script.php
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
Input Post Code:</br><input type="text" name="code" size="30">
<input type="submit" name="submit" value="submit">
</form>
<?php
//Connect to the database
include 'connect.php';
//If the form has been submitted then process the form
if (isset($_POST['code'])) {
//Grab the Postcode from the form
$postcode = $_POST['code'];
//Convert the Postcode to all uppercase
$postcode = strtoupper($postcode);
//Break the Postcode into
list($outcode, $partTwo) = split(' ', $postcode);
//Pull out the relevant fields from our database
$query = "SELECT latitude,longitude FROM hwz_postcodes WHERE outcode= '$outcode'";
$result = mysql_query($query) or die('Query failed: '.mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
//Print Results
print $postcode.' : ';
print $line['latitude'];
print ',';
print $line['longitude'];
//We've finished with the database, so close the connection
mysql_close($conn);
}
?>
The Easypeasy Database
Today I've been testing the Easypeasy database for my widget project.
I began by installing the data to MySQL. Very easy to do as the downloadable zip comes with a file you can import directly into MyAdmin.
With the database installed I used two scripts to look at the data in more detail. Firstly, one to establish the initial database connecion – it’s an idea to keep this file separate so you only have to write it once. Then, a second script that builds a form and processes the results.
Once I started to plot my results it quickly became apparent that although Latitude and Longitude is returned for each entry, the numbers are all rounded up. This puts W10 and SE13 on the same spot, so there's still a bit of work to do to figure out how to the x and y fields effect the results.
Here’s the code I wrote for the form:
<form action="<?php echo $_SERVER['PHP_SELF']?>" method="post">
Input Post Code:</br><input type="text" name="code" size="30">
<input type="submit" name="submit" value="submit">
</form>
<?php
//Connect to the database
include 'connect.php';
//If the form has been submitted then process the form
if (isset($_POST['code'])) {
//Grab the Postcode from the form
$postcode = $_POST['code'];
//Convert the Postcode to all uppercase
$postcode = strtoupper($postcode);
//Break the Postcode into two
list($outcode, $partTwo) = split(' ', $postcode);
//Pull out the relevant fields from our database
$query = "SELECT latitude,longitude FROM hwz_postcodes WHERE outcode= '$outcode'";
$result = mysql_query($query) or die('Query failed: '.mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
//Print Results
print $postcode.' : ';
print $line['latitude'];
print ',';
print $line['longitude'];
//We've finished with the database, so close the connection
mysql_close($conn);
}
?>
Background:
After playing around with Google maps for a few days it has become apparent that having a list of UK postcodes plus the corresponding latitude and longitude to each would come in very handy fro a lot of people. If you had such a thing you could build loads of exciting applications, from route planning to food mile calculators.
The problem is that here in the UK the list doesn’t exist in the public domain. It’s available from the Post Office, but it’ll cost you, making it effectively useless for most small groups and enterprises.
What’s currently available from Easypeasy is the first half of the code. With this you can break the UK into about 3,000 separate parts, narrowing a location to within a few kilometres.
Project Brief:
There appear to be two groups pushing the Postcode into the public domain, Free the Postcode and New Popular Edition Maps.
What I’d like to do is build a widget that people can put on their website that makes it easy for the general public to enter their Postcode, and help build the free database. Currently you are required to specifically visit either of the two website and with Free the Postcode know by heart your latitude and longitude.
Using the Google Map API combined with the first half of the postcode the widget would pull up a map of your local area, from here it’s easy to stick a pin where you live or work, and then after an email authentication your postcode is added to the database.
Refrenceces:
Free the Postcode: www.freethepostcode.org/
New Popular Edition Maps: www.npemap.org.uk/
Postcode Schema: www.govtalk.gov.uk/gdsc/html/frames/PostCode.htm
Easypeasy: www.easypeasy.com/guides/article.php?article=64
Making your own Google Maps is an extremely useful thing to know how to do. And more importantly as it requires such a bare minimum coding you can produce practical and interesting maps in no time. After an hour I had mapped the extent of The Originals empire in classic James Bond villain style.
You can see it here.
Firstly get yourself a Google account, the get yourself down here to get your API key:
http://www.google.com/apis/maps/signup.html
Once you’ve got this you can start building your own maps.
There is some good documentation to get you going here:
http://www.google.com/apis/maps/documentation/#The_Basics
Here’s the source from my map:
//Initialize the map
var map = new GMap2(document.getElementById("map"));
//Add the Zoom and Pan Control
map.addControl(new GSmallMapControl());
//Add the Map, Satellite, Hybrid Control
map.addControl(new GMapTypeControl());
//Set up my Locations
var theOriginals = new GLatLng(51.5189,-0.2139);
var tobyLA = new GLatLng(34.38,-118.1434);
var pete = new GLatLng(-23.3148,-46.3748);
var hans = new GLatLng(55.3636,13.112);
//Center map around a Location, set zoom
map.setCenter(theOriginals, 1);
// Create a custom Map Pin icon
var icon = new GIcon();
icon.image = "http://www.wearetheoriginals.co.uk/images/pin.png";
icon.iconSize = new GSize(20, 25);
icon.iconAnchor = new GPoint(10, 25);
icon.infoWindowAnchor = new GPoint(5, 1);
//Attach icons to all my Locations
map.addOverlay(new GMarker(theOriginals, icon));
map.addOverlay(new GMarker(tobyLA, icon));
map.addOverlay(new GMarker(pete, icon));
map.addOverlay(new GMarker(hans, icon));
//Draw a 2px yellow line between my Locatons
var points = [theOriginals,tobyLA,theOriginals,pete,theOriginals,hans];
map.addOverlay(new GPolyline(points,'#FFFF33',2));
//And relax…
If your Flash application needs to talk to an XML file, the Flash XML Connector is just what you've been looking for.
Instead of having to write a tiresome routine to parse your XML file this little widget does all the hard work for you. Ideal for lazy coders like myself.
As an example we’ll connect an external XML file (data.xml) to an XML Connector in Flash, and then we’ll connect this to a list component - our aim is to populate the list with values from the XML file.
You can use this file as your XML source.
To begin with open Flash, make a new document and save it to the same folder as your XML file.
From the Components panel > drag an XMLConnector to stage, name it ‘myConnector’.
From the Properties panel > set URL to ‘data.xml’ > Set the direction parameter to receive.
Now with the Component Inspector panel > Schema tab > Click ‘results : XML’ > Click the Import button (to the right of the tab) > Browse to the data.xml file > Click ‘bands : Array’
Next from the Components panel > drag a List component to stage, name it ‘myList’.
With the Component Inspector panel Select list > Bindings > + > dataProvider : Array > The direction parameter should be set to in > Click the bound to value field > XMLConnector > ‘bands : Array’.
Now on frame 1 add the following script: myConnector.trigger()
And you’re done.
If you'd like to style your new list componenttry this.