Danny Kopping
This user hasn't shared any biographical information
Posts by Danny Kopping
XAMPP 1.7.2 Released
Aug 20th
It’s finally here! The new version of the XAMPP stack has been released…
This new version includes PHP 5.3.0, Apache 2.2.12, MySQL 5.1.37 & phpMyAdmin 3.2.0.1 (amongst a myriad of other features). You can check out the new stack here. I wouldn’t recommend upgrading if you are using AMFPHP or CodeIgniter as the new version of PHP (5.3.0) will mess up quite a few things – i learnt the hard way.
I upgraded from 1.7.1 to the new version on my Linux Mint virtual server that i run within my Vista installation (damn you Adobe! Just release your software on Linux already!) and i came across an error in one of my AMFPHP installations on a project that i’m working on at the moment:
(mx.rpc::Fault)#0
errorID = 0
faultCode = “Client.Error.DeliveryInDoubt”
faultDetail = “Channel disconnected before an acknolwedgement was received”
faultString = “Channel disconnected”
message = “faultCode:Client.Error.DeliveryInDoubt faultString:’Channel disconnected’ faultDetail:’Channel disconnected before an acknolwedgement was received’”
name = “Error”
rootCause = (null)
I think that AMFPHP is still the simplest and easiest way to use Flex remoting with PHP (i recently wrote an article for FFDMag on this topic – look out for it in the September edition). However, it doesn’t have the greatest error handling mechanism ever…
Using Charles Proxy, i managed to find the real root of the error, and it appears that there is some sort of discrepancy with the dates/timezones in Gateway.php in the core of AMFPHP.
To resolve this issue, open the Gateway.php file in the core/amf/app folder in your AMFPHP installation and go to line 213. You need to tell PHP which timezone you’re in, and you can paste the following code:
date_default_timezone_set("Africa/Johannesburg");
above this line:
$dateStr = date("D, j M Y ") . date("H:i:s", strtotime("-2 days"));
I reside in Johannesburg, South Africa so that timezone will apply to me, but if you live anywhere else, you’ll have to find the pertinent timezone to use.
That should fix things up…
Runtime Shared Libraries – indispensable and infuriating!
Jul 22nd
Utilizing the RSL (Runtime Shared Library) mechanism in Flex is arguably one of the quickest and easiest ways to drastically shrink your Flex application’s file size. The RSL mechanism essentially allows you to compile your Flex application without embedding the Flex framework into the code. So, if the Flex framework isn’t compiled into the Flex application (final SWF file), then how does the application work? The real genius comes in at this point… The Flash Player – as of version 9.0.60 – can now cache signed RSLs containing the Flex framework. If the Flash Player caches these frameworks, it means that if you have viewed a Flex site using the 3.2.0 SDK and you launch another Flex application using the same SDK, you do not have to download the whole framework from the server!
For more information and a brief tutorial, visit this link on the Adobe Labs site.
However, it’s not always as quick and easy as some might like to believe. Recently i’ve been playing around with RSLs and different versions of the Flex SDK and i’ve been encountering the dreaded Error #1001 runtime error. This pernicious and convoluted little error can cause a spontaneous force of attraction between your forehead and your desk. It’s quite strange indeed… Well, after a bit of digging and some messing around, i seem to have noticed a general pattern for failure and subsequently getting the error message above, and how to fix it…
I’ve created a Flex project and have merrily gone about my day coding, styling, flexisizing etc… I’ve set my project to use RSLs (using the 3.2.0 Flex SDK) and everything is working just fine. Now i notice on the Adobe Labs site that there’s a new Flex SDK available (say… 3.3.0). I decide to chuck the current SDK and replace it with the new one… Only to see the following after a compile of the project:
Eek. Nothing like a good ol’ spanner in the works, eh?
After a bit of scratching around in the 3.3.0 SDK folder, i came upon the flex-config.xml file (located at $FLEX_INSTALL_PATH/sdks/$SDK_VERSION/frameworks). If you scour through the file, you’ll see that towards the bottom there’s a node called runtime-shared-library-path. Here’s what it looks like in the 3.3.0 SDK:
<runtime-shared-library-path> <path-element>libs/framework.swc</path-element> <rsl-url>framework_3.3.0.4852.swz</rsl-url> <policy-file-url></policy-file-url> <rsl-url>framework_3.3.0.4852.swf</rsl-url> <policy-file-url></policy-file-url> </runtime-shared-library-path>
Check out the two rsl-url properties… One is the name of a SWZ (signed SWF) file and the other is a plain SWF file… Notice the naming of those URLs and then refer back to the image above. Flex Builder obviously didn’t change the RSL linkages when i changed my SDK in my Flex project.
The SOLUTION:
Open your Flex Project Properties dialog, select the Flex Build Path option on the left, then the Library Path tab at the top. You will then see something like this:
Notice how the version numbers of the RSL files do not correlate with the version of Flex SDK? For some reason, Flex doesn’t change the RSL linkage when you switch SDKs in a Flex Project. I wonder whether this is a bug or a feature (like i often wonder about the ON button on Windows machines).
Anyway, the quick fix for this is as follows:
Simple select the Flex SDK and hit the REMOVE button on the right. The Add Flex SDK button will then become active and you can go ahead and click on it. This will scan the flex-config.xml file we looked at earlier and pick up the correct files to use for the RSL.
Done! You can now close the Properties dialog.
Go ahead and clean your project at this point by going to the menu, Project -> Clean. This will delete all the compiled code that was previously generated and it will then trigger a new build. Once the build has completed, run your Flex application…
Oh, don’t you just love it when shit works?!
Formatting your Flex code in Flex Builder 3
Jul 9th
Oftentimes i will be searching the net for a useful class or code snippet, only to be horrified by its inherently ugly formatting. I’m obsessed with code neatness and readability, and it really pisses me off when i have to reformat an entire class by hand.
Enter Flex Formatter from Ernest Pasour
This incredibly useful little set of three plugins for Flex Builder 3 (and possibly Flash Builder 4 – i haven’t tried yet, can someone confirm this?) provides you with a vast variety of code formatting options. Below is a couple of screenshots of the configuration pages:
ActionScript
MXML
Even apart from all of its amazing code reformatter tools, FlexFormatter 0.6.24 has the ability to generate ASDoc comments! By now you should be convinced, so here’s the installation process:
- Download zip file from here
- Unzip contents (3 .jar files) to your plugins directory inside of your Flex Builder 3 installation
- Restart Flex Builder and you will notice there will be 5 new buttons in your toolbar:
Happy formatting!
Union Platform – Part I (Installation)
Jul 8th
We’ve all heard about Colin Moock at some point in our Flash/Flex development career. Colin has authored a great many ActionScript books throughout the years and as a consequence has helped thousands – including myself – to learn ActionScript. Now Colin has hit the community with something incredible… the Union Platform.
Here is the official definition of the Union Platform from http://www.unionplatform.com: “Union is a development platform for creating multiuser applications. It includes the Union Server, a multiuser communications server, and Reactor, a framework for creating Adobe Flash client applications.”
Essentially what this means is… you can now build realtime chat applications, MMORPG games, and anything else that could use a little realtime flavour
Installation
In this part of the series on the Union Platform i will be showing you how to install the Union server on your *nix machines and Window$ machines. Let’s leave the hideous beast (Window$) for last, and begin with a real operating system that is actually a pleasure to work with, and doesn’t make you praise whichever god you worship that your legs can’t bend backwards at the knees to kick yourself in the balls for ever getting roped into that shitty OS.
I’ll be Linux Mint for my *nix installation explanation, and this will work on Macs too in much the same way.
The Union Platform Server is a Java application that will run on your server and listen on port 9100 and 9101 for traffic. Be sure to check that your firewall doesn’t block this port before you begin…
First things first, head over to the downloads page on the Union site and download the GZipped tarball to your desktop.
Next, unzip the tarball’s contents (tar -xf union_1.0.0_alpha2.tar.gz). This will create a folder called union on your desktop. Now, move either the folder in its entireity or the contents to a folder somewhere on your machine.
Perfect. So now we have all the files we need. Make sure that you have Java installed and working correctly on your machine or otherwise this will not work. You will need to make sure that this folder had execute permissions, so issue the command chmod 775 * to give all the files the necessary permissions.
Usage
Once this is done, we’re done! To start the Union Platform Server issue this command: ./startserver.sh from inside the folder you unzipped. You will now see your terminal bombarded with debug messages notifying you of Union‘s successful start.
Window$ users please note: the instructions above are pretty much the same for Window$; merely extract the files to your machine and run the batch file startserver.bat.
Administration Panel
Colin Moock and crew have been generous enough to provide us with a Flex administration panel for the server, and you can find it here. Download the SWF, and open it in your browser. You will be met with a login screen like this:
NOTE: If you look in the union.xml configuration file, you will find the password that is used by the server. By default it is password. Also note that the administration panel runs on port 9110.
Once you have logged in, you will see a screen like this:
Pretty bloody cool if you ask me!
Join me in the next part of this series when i will be demonstrating how to build a simple realtime chat application!
An interesting Math problem…
Jun 9th
If:
2 + 2 = 4,
3 + 2 = 5,
3 + 4 = 14,
4 + 2 = 18 and
5 + 3 = 40
What is 6 + 3?
I’ll announce the answer in a week. Post a comment below if you think you have the answer
UPDATE
So, after a week, JP was the only one to get the correct answer!
If:
2 + 2 = 4, (common multiple = 1)
3 + 2 = 5, (common multiple = 1)
3 + 4 = 14, (common multiple = 2)
4 + 2 = 18 and (common multiple = 3)
5 + 3 = 40 (common multiple = 5)
What is 6 + 3?
As you can see, the common multiple for each line of equation evaluates to a Fibonacci sequence (starting at 1), and the last common multiple was 5, so the next one will be 8, therefore:
6 + 3 = 9 * 8 = 72
Design, Develop, Debug, Deploy
Jun 1st
Just in case you’ve had your head stuck in the ground for the past few hours and haven’t yet heard the news, i’m thrilled to announce that Adobe Flash Builder 4 (previously named Flex Builder) and Adobe Flash Catalyst (codenamed Thermo) have been released in beta on Adobe Labs! The two new applications are set to completely revolutionize the industry with their incredible new features and vastly improved workflows.
Check out the Adobe Labs website and http://labs.adobe.com/technologies/flash/videos/ for more information and downloads. Happy Flashing!
![]() |
![]() |
JSON Utility 0.1 Released!
May 31st
I have just created an application (still a very early version!) that is aimed at making development with the JSON data-interchange format a whole lot easier. This application basically accepts a JSON string, validates it (using the JSONDecoder class from as3corelib) and generates an ActionScript 3.0 class from it. You can download it here!
The opening screen:
…and the output!
I’ve got quite a few more features planned (hence the version “0.1″). If you have any comments, queries or suggestions, leave them in a comment below.
Thanks to Dan White for the use of his skin Granite!
Parsing XML in PHP5 with SimpleXML
May 16th
PHP5 includes a library for parsing XML data called SimpleXML. This class (and associated classes) is a fantastic way to parse XML data in PHP5. Parsing of XML comes into almost every project i work on, whether it be creating/manipulating RSS feeds, sending data between Flex and PHP, and whatever else the client wants really
Below is the XML data i will be working with in this tutorial:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <languages> <language year="1999"> <name>ActionScript 3.0</name> <description>ActionScript is a scripting language based on ECMAScript. ActionScript is used primarily for the development of websites and software using the Adobe Flash Player platform (in the form of SWF files embedded into Web pages).</description> </language> <language year="1995"> <name>PHP</name> <description>PHP is a scripting language originally designed for producing dynamic web pages. It has evolved to include a command line interface capability and can be used in standalone graphical applications.</description> </language> <language year="1995"> <name>Java</name> <description>Java is a programming language originally developed by James Gosling at Sun Microsystems and released in 1995 as a core component of Sun Microsystems' Java platform. The language derives much of its syntax from C and C++ but has a simpler object model and fewer low-level facilities. Java applications are typically compiled to bytecode that can run on any Java virtual machine (JVM) regardless of computer architecture.</description> </language> <language year="2007"> <name>LOLCODE</name> <description>LOLCODE is an esoteric programming language inspired by the language expressed in examples of the lolcat Internet meme. The language was created in 2007 by Adam Lindsay, researcher at the Computing Department of Lancaster University.</description> </language> </languages> |
Now, say we wanted to parse this XML file using PHP, and extract the name of each of these languages…
1 2 3 4 5 6 | <?php $languages = simplexml_load_file("languages.xml"); foreach($languages as $language) echo $language->name."<br/>"; ?> |
In the above code, one can extrapolate that SimpleXML will go through your XML file and assign the nodes to an array, and in that array it will create an untyped Object with the data assigned to properties of that Object.
Simple enough, right?
Now, what if you wanted to access an attribute of each of these languages (in this scenario – the year attribute of each language)?
That’s also really easy with SimpleXML! You can reference the attributes of each node by using array notation…
1 2 3 4 5 6 | <?php $languages = simplexml_load_file("languages.xml"); foreach($languages as $language) echo $language["year"]."<br/>"; ?> |
Ok. So what if you wanted your returned data to be mapped to a class? I.e. each element in the array that is returned must be strongly typed to a class, rather than the unspecific stdClass Object that’s returned by default… This can also be done with SimpleXML!
Here’s the Language.php class i created for the returned array elements to be typed as (note that it ,must extend the SimpleXMLElement class):
1 2 3 4 5 6 7 8 | <?php class Language extends SimpleXMLElement { public $year; public $name; public $description; } ?> |
…and the code to return each array element as a Language Object:
1 2 3 4 5 6 7 8 9 | <?php require_once("Language.php"); $languages = simplexml_load_file("languages.xml", "Language"); foreach($languages as $language) { print_r($language); } ?> |
If you look at the output, you will see that the year attribute is not assigned to $year property of the Language class, but rather to a @attributes property. However, if you add this function to the Language.php class, the attributes will be assimilated to their respective properties:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | <?php class Language extends SimpleXMLElement { public $year; public $name; public $description; public function attrToProp() { foreach($this->attributes() as $prop => $val) $this->$prop = (string) $val; } } ?> |
…and run the script again, but adding this line of code:
1 2 3 4 5 6 7 8 9 10 | <?php require_once("Language.php"); $languages = simplexml_load_file("languages.xml", "Language"); foreach($languages as $language) { $language->attrToProp(); // -- add this line print_r($language); } ?> |
Using Conditional Statements with MySQL
May 14th
While working on a project, i got lazy (as i always do…); I didn’t feel like fetching an array of rows from MySQL and filtering the data in PHP according to a condition… Too much of a ballache to be honest. I thought: ‘Fuck it… Let’s see if one can use conditional statements in MySQL‘.
After doing a little research, i came across this page (http://dev.mysql.com/doc/refman/5.0/en/control-flow-functions.html). After scouring through the normally indecipherable MySQL reference manual, i managed to get the hang of it…
Although the scenarios where the application of this functionality are few and far between, i felt it’d still be a cool idea to share this (seemingly) arbitrary tit-bit.
Consider the following scenario…
You have a table of users. In this table, you keep the following information about each user:
- name
- surname
- gender
Now, depending on the gender of your user, you would like to return their details with a certain prefix, namely Mr for a male or Ms for a female. Here’s the database structure, and two rows of sample data:
CREATE TABLE IF NOT EXISTS `users` ( `name` VARCHAR(255) NOT NULL, `surname` VARCHAR(255) NOT NULL, `gender` enum('M','F') NOT NULL ) ENGINE=MyISAM DEFAULT CHARSET=latin1 ROW_FORMAT=DYNAMIC; -- -- Sample data -- INSERT INTO `users` (`name`, `surname`, `gender`) VALUES ('Joe', 'Shmo', 'M'), ('Jane', 'Shmane', 'F');
…and here’s the SQL query
SELECT *, CONCAT(IF(gender = "M", "Mr ", "Ms "), name, " ", surname) AS fullName FROM users
If that looks a little too indecipherable/complicated, here’s the previous query in a more simplified (albeit less efficient) way:
SELECT *, IF(gender = "M", CONCAT("Mr ", name, " ", surname), CONCAT("Ms ", name, " ", surname)) AS fullName FROM users
Essentially the IF() statement is structured like this:
IF(condition, true code, false code)
However, you can place an IF statement anywhere in a query (from what i can tell thus far), it gets executed in place and is replaced by either the true code or the false code.
Another (much simplified) example:
SELECT IF(1 > 0, "TRUE!", "FALSE!");
…and that’s conditionals with MySQL!













