Archive for April, 2009
Flex Builder 3 for Linux has been canned! Show your support!
Apr 28th
I was recently shocked and appalled to see that Adobe has put the development on Flex Builder 3 for Linux on hold. I, for one, would really love to be able to develop Flex applications on Linux (I use Linux Mint) and – in addition – would like to see a Creative Suite release for Linux soon, too.
Personally i can’t think why developing a version of Flex Builder for Linux would be so difficult. Flex Builder is built on top of (and as a plugin for) Eclipse, which is Java-based and therefore cross-platform. I’d imagine that it does have something to do with the Flash Player as Tom of rachaelandtom.info says. Can anyone shed some light on the situation?
The reason for Adobe’s suspension of development is:
“The project is currently on hold. There is not enough requisition for the product to continue its development” – Ben Forta (Adobe Senior Technical Evangelist)
Please show your support and vote for the continuation of this amazing project! Go to http://bugs.adobe.com/jira/browse/FB-19053 and vote!!
Using MySQL and JSON
Apr 25th
JSON has – over the past few months – start working its way more and more into my daily life as a web developer. I find myself using it for all sorts of solutions, whether i’m using ActionScript or PHP. For those of you who don’t know, JSON stands for JavaScript Object Notation. JSON is an extremely lightweight, human-readable and highly compacted data-interchange format. JSON works on the principle of name/value pairing, and it’s very easy to read, write and parse.
A typical JSON representation of the following PHP object would be:
{"title":"Using MySQL and JSON","date":"25 April 2009","timeOfWriting":"15h34"}
1 2 3 4 5 6 | <?php $blogPost = new stdClass(); $blogPost->title = "Using MySQL and JSON"; $blogPost->date = "25 April 2009"; $blogPost->timeOfWriting = "15h34"; ?> |
and the following ActionScript object would also be represented as it was above:
1 2 3 4 5 6 7 | var blogPost:Object = new Object(); blogPost.title = "Using MySQL and JSON"; blogPost.date = "25 April 2009"; blogPost.timeOfWriting = "15h34"; // -----or----- //var blogPost:Object = {title:"Using MySQL and JSON", date:"25 April 2009", timeOfWriting:"15h34"}; |
JSON can be extremely useful when you want to pass data from any platform to any other platform as the format is – essentially – just plain ol’ text and computers can parse JSON objects very easily.
In PHP5, this is supported natively, using the json_encode and json_decode functions.
However, in ActionScript 3.0, the parsing of JSON strings is not supported in the native ActionScript 3.0 API, so you can either write one yourself or use the JSONEncoder or JSONDecoder classes found in the as3corelib package.
Here’s how to encode/decode a JSON string in PHP:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | <?php $blogPost = new stdClass(); $blogPost->title = "Using MySQL and JSON"; $blogPost->date = "25 April 2009"; $blogPost->timeOfWriting = "15h34"; // -----or----- // $blogPost = array("title" => "Using MySQL and JSON", // "date" => "25 April 2009", // "timeOfWriting" => "15h34"); $json = json_encode($blogPost); echo "Encoded JSON: ".$json; echo "<br/>Decoded JSON (as associative array):<br/>"; print_r(json_decode($json, true)); echo "<br/>Decoded JSON (as stdClass object):<br/>"; print_r(json_decode($json)); ?> |
…and in ActionScript 3.0 using the as3corelib package:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import mx.utils.ObjectUtil; import com.adobe.serialization.json.JSONDecoder; import com.adobe.serialization.json.JSONEncoder; var blogPost:Object = new Object(); blogPost.title = "Using MySQL and JSON"; blogPost.date = "25 April 2009"; blogPost.timeOfWriting = "15h34"; // -----or----- //var blogPost:Object = {title:"Using MySQL and JSON", date:"25 April 2009", timeOfWriting:"15h34"}; var json:String = new JSONEncoder(blogPost).getString() trace("Encoded JSON: " + json); trace("Decoded JSON: " + ObjectUtil.toString(new JSONDecoder(json).getValue())); |
Now that we’ve gotten that out of the way, let’s have a look at how we can use JSON inside of MySQL. First off, let me say that i’m a big fan of structuring one’s databases correctly and not taking hideous shortcuts like i’m about to show you, but sometimes doing this hideous shortcut might actually help you develop your appplications faster, and keep things extensible.
I’ve found that i often have to keep changing my database structure when clients have changes of heart (and man, do they change them often!). It becomes extremely frustrating to have to restructure an entire database (and all associated PHP/AS3 code) every time a client remembers that he forgot about needing to store something as ridiculous the big-toe girdths of his future website’s users.
Now, i’m certainly not a patient person, and – to be honest – i don’t have time to fuck about and keep changes logic just to accomodate menial extra pieces of info. What i do therefore is usually keep a settings column in the users table, set it’s type to Text and store JSON strings in there to keep track of all the silly idiosyncratic (and sometimes idiotic) requirements of the client. Then all i have to do is parse out that string and apply some business logic to the values i find in that row under the settings column.
I find that it makes things a lot simpler and with orders of magnitude less ballaches.
What do you think?
Using PHP to Backup and Save your MySQL Database
Apr 17th
While working on a recent project, i needed to set up a cron job that would run every X amount of hours and backup a database. I’ve done this a few times before, but only this time (while Googling for a better solution) i found David Walsh‘s blog post on how to Backup Your MySQL Database Using PHP. David’s done a great job and i definitely recommend you check his blog out in its entireity for some really neat web dev articles.
I decided to go and put David’s script into class form (my case of OCD is genuine
) and i added one or two things to it. Basically it allows you to backup one or many tables in a database, include or exclude the data from the backup and i also included Rick Ellis’ (of CodeIgniter fame) Zip class to allow you to zip up the backup and stash it somewhere.
Thanks to David Walsh and Rick Ellis!
Here’s the class: DatabaseDump.php
…and here’s how to use it:
$dump = new DatabaseDump("host", "user", "password", "database", "destination/"); $dump->backup();
Be sure to check out the DatabaseDump.php class for the documentation!
5 Web Development Tools I Can't Live Without
Apr 15th
Web development isn’t about being so uber-cool that you can code a whole site with Notepad/TextMate; it’s about utilizing the right tools for the right job for the quickest, most efficient result.
The tools mentioned below many not all help directly with development, but they all play a major part in my development lifecycle.
- Prevent Duplicate Tabs – one of the simplest but insanely useful plugins for Firefox. Really, really useful when coding/testing with Flex!
- Firebug – the ultimate HTML/CSS/JavaScript tweaking tool that integrates with Firefox
- Web Developer – a great collection of nifty little tools that makes your web development go that much easier (I definitely recommend the Disable Cache feature when doing Flash/Flex work)
- PowerMenu - a great little tool that allows you to minimize any window to the tray, amongst other things (Windows only)
- Taskbar Shuffle – for when you’re forced to work on Windows
(i’m extemely obsessive about the order of my windows for some reason…)
And just for good measure, check out DownThemAll – an amazing download manager for Firefox.
What tools do you use?
Using Modules with Preloaders
Apr 11th
Here’s a quick and dirty way to show a preloader while your module loads:
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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 | <?xml version="1.0" encoding="utf-8"?> <mx:ModuleLoader xmlns:mx="http://www.adobe.com/2006/mxml" currentState="loading"> <mx:states> <mx:State name="loading"> <mx:SetStyle name="horizontalAlign" value="center"/> <!-- Align progress bar to center --> <mx:SetStyle name="verticalAlign" value="middle"/> <!-- Align progress bar to middle --> <mx:AddChild position="lastChild"> <mx:ProgressBar id="progressBar" labelPlacement="center" mode="manual"/> </mx:AddChild> </mx:State> </mx:states> <mx:Script> <![CDATA[ import mx.modules.IModuleInfo; import mx.events.FlexEvent; import mx.modules.ModuleManager; import mx.events.ModuleEvent; private var module:IModuleInfo; override public function loadModule():void { if (url == null) return; if (child) return; if (module) return; dispatchEvent(new FlexEvent(FlexEvent.LOADING)); module = ModuleManager.getModule(url); module.addEventListener(ModuleEvent.PROGRESS, moduleProgressHandler); module.addEventListener(ModuleEvent.SETUP, moduleSetupHandler); module.addEventListener(ModuleEvent.READY, moduleReadyHandler); module.addEventListener(ModuleEvent.ERROR, moduleErrorHandler); module.addEventListener(ModuleEvent.UNLOAD, moduleUnloadHandler); module.load(applicationDomain); } private function moduleProgressHandler(event:ModuleEvent):void { dispatchEvent(event); try { progressBar.setProgress(event.bytesLoaded / event.bytesTotal, 1); } catch(e:Error) { } } private function moduleSetupHandler(event:ModuleEvent):void { // Not ready for creation yet, but can call factory.info(). dispatchEvent(event); } private function moduleReadyHandler(event:ModuleEvent):void { child = module.factory.create() as DisplayObject; dispatchEvent(event); if (child) { var p:DisplayObjectContainer = parent; // p.removeChild(this); addChild(child); setStyle('horizontalAlign', ''); // Reset horizontalAlign setStyle('verticalAlign', ''); // Reset verticalAlign currentState = ''; } } private function moduleErrorHandler(event:ModuleEvent):void { unloadModule(); dispatchEvent(event); } private function moduleUnloadHandler(event:ModuleEvent):void { dispatchEvent(event); } override public function unloadModule():void { if (child) { removeChild(child); child = null; } if (module) { module.removeEventListener(ModuleEvent.PROGRESS, moduleProgressHandler); module.removeEventListener(ModuleEvent.SETUP, moduleSetupHandler); module.removeEventListener(ModuleEvent.READY, moduleReadyHandler); module.removeEventListener(ModuleEvent.ERROR, moduleErrorHandler); module.unload(); module.removeEventListener(ModuleEvent.UNLOAD, moduleUnloadHandler); module = null; } } ]]> </mx:Script> </mx:ModuleLoader> |
Or you can download the file here.
howto.ria-coder.com opened!
Apr 10th
Following from the Flex Examples Blog, i decided to create my own forum where anybody can read and write howtos pertaining to Flash, Flex and PHP. I will probably be adding new forum topics in the near future, but for the moment these three will be the focus of howto.ria-coder.com.
I will be updating the forum periodically – adding new howtos as often as i can. You are all more than welcome to add your own howtos as well, but please respect the open nature of the forum.
I hope that this forum will help you all.
A serious case of 'Wobble You Tea Eff'
Apr 2nd
Ok. I’ve seen some weird shit in my days, but this post that i stumbled upon from Aral Balkan has completely confuckulated me.
I was doing a bit of research on finding the created children inside of a Repeater component. Now, the Repeater component is extremely useful but it can be one helluva irritating component to work with. I dug down into the Flex source and found a variable in there (an array called createdComponents) that set off those heaven bells (you know… like when the clouds part and angels descend in the movies)… Alas, it’s a protected variable!!! Noooooooooooooooooooooooo!
So where to now? Do i edit the source and recompile Flex and risk stuffing something up (not mention wasting precious, fleeting time) or do i try and find another solution?
In my days as a Flex developer, i’ve used the Repeater component several times and i always find a way around the inability to get an array of created components (doesn’t it seem logical to include a function for that??). But the solutions i’ve found were all dirty and hackerish, and everytime i use them i feel like i’m coming out of parliament (dirty, oh so dirty)… and then, Mr Balkan comes along and completely saves my mental hygiene, but it’s left me with a serious case of the wobble-you-tea-effs.
What he has done is given each repeated component an id (which seems pointless since one would imagine that it would be of no use since each repeated component is the same) and from that id, a global array gets created out of nowhere (henceforth referred to as the pulling an array out of an orifice method) and you can then access the created components using that id. Odd
, deeply deeply odd
(unless i’m missing something that somebody can point out).
Here’s an example:
1 2 3 4 5 6 7 8 9 | <mx:Array id="someArr"> <mx:String>Button A</mx:String> <mx:String>Button B</mx:String> <mx:String>Button C</mx:String> </mx:Array> <mx:Repeater id="repeater" dataProvider="{someArr}" recycleChildren="true"> <mx:Button id="buttons" label="{repeater.currentItem}"/> </mx:Repeater> |
And then you can access the buttons variable as an array! Each element in the array refers to each component repeated by the Repeater component.
Strange…
Props to Aral Balkan for helping me out!