Skip to Content »

 Cool MySQL increment/decrement value tip

  • September 28th, 2008
  • 7:34 pm

I needed to adjust a value in a column in a database table by 1, for all rows. I found out you can do it easily by doing this:

PHP:
  1. $sql = "UPDATE images SET displayIndex=displayIndex +1 WHERE gallery_id=1";

Turning that into a function we can specify if we want to increment or decrement the value pretty easily. You can also provide a starting point for the adjustment (so if you delete the item with displayIndex=15, you only want to decrement the displayIndexes greater than 15 by 1) and specify a different value for the WHERE clause:

PHP:
  1. public function updateDisplayIndexes($galleryID, $startIndex, $add = true){
  2.    
  3.     $operator = ($add) ? '+' : '-';
  4.  
  5.     $sql = "UPDATE images SET displayIndex=displayIndex".$operator."1 WHERE gallery_id=$galleryID AND displayIndex> $startIndex"
  6.     $result = mysql_query ($sql);
  7. }

There's a lot more you can do with it but it's been a pretty good starting point.

 Adobe Announces CS 4

  • September 23rd, 2008
  • 12:16 am

Adobe has new info up about the upcoming release of their CS 4 suite. Checked out the Flash content, I'm a little ambivalent...the new features don't really do too much for me, though I have to admit it's nice to see Flash get back to more of it's animation roots. I wonder if they're going to revamp the component architecture again?

 Dropbox rocks

  • September 16th, 2008
  • 11:25 am

If you haven't yet checked out Dropbox, the slick file transfer/sharing/backup tool, you should. It's one of those things that reminds me that computers supposed to be here to make our lives easier, not harder. It's so easy, even my wife was excited about it ("Cooooolll !!!" :) )

Dropbox installs on your computer and completely integrates with the filesystem...it's actually just a folder (your 'Dropbox') you drag files into. In your dropbox you have a public folder, and once you drop a file within the public folder, you can right-click on get the web URL for that file. You can then send that url to anyone you like and they can view that file.

In addition to your Public folder, there is a 'Photos' folder. Dropping images (or a folder of images) into that folder will create a public photo gallery with thumbnails.

You can also create Shared folders within your Dropbox, to be shared only with specific people.

Your drop box also keeps a version history of your files, so you can roll back to a previous version, a la Time Machine.

There are two small downsides I can see so far with Dropbox. First, as of right now they have a 2 gigabyte limit. Two gigs of backup for free is not that bad I guess, but I think 5 would be a better starting point. Regardless of that, they will soon be offering paid plans to increase storage, and I'll be jumping on that immediately...goodbye local hard drive backup.

The other issue I have is that you must place everything within your Dropbox....so for example, if you wanted to share your Iphoto library you would need to copy the images into your Dropbox. I think they are working on allowing for watched folders as well. Mac (and I'm assuming linux) users can get around this by creating symbolic links in the dropbox.

Overall, 4-stars, two thumbs way up for Dropbox.

Note: I have no affiliation with Drobox, it's just love at first sight.

 Dear Adobe - Thanks for the 32gb iPod Touch!

  • September 9th, 2008
  • 10:03 am

A while ago I filled out a survey for Adobe which was offering 32 gb iPods as a prize to random submissions. The other day FedEx dropped one off...woo-hoo! That'll sure motivate somebody to fill out future surveys :)

Thanks again!

 Wow - I’m somebody’s Dad!

  • September 4th, 2008
  • 9:46 am

Last Friday my wife and I welcomed our first child, a boy, into the world. He was born happy, healthy, and, of course, is the most beautiful baby ever to be born in the history of mankind :) . Seriously though, he is absolutely fascinating, I can sit there and just watch him and be completely entertained for hours. Now I can relate to all the dads I spoke to before who kept telling me there's just nothing else like it...they were absolutely right, it's indescribable.

 Flex + AMFPHP: Mapping Value Objects

  • August 2nd, 2008
  • 5:09 pm

Update: Added code samples to end of post.

One of the issues I see a lot of with people using AMFPHP is how to properly map VO classes between Flex and php. It used to stress me out too, until I realized how easy it really is.

First thing: Don't worry about the package paths in the RemoteClass metadata tag and $_explicitType variables in your php classes. You don't need them.

Second thing: Just use the name of the class you are mapping in for the values RemoteClass("alias="") and $_explicitType="". For example, if you wanted to map a value object named 'Book' between flex and php, just use:

Actionscript:
  1. [RemoteClass(alias="Book")]

and

PHP:
  1. var $_explicitType="Book";

Like i already mentioned, you don't need the package names. The reasons behind this are:

  • When sending from php to Flex, Flex will match the $_explicitType variable to the Remote class alias. It's just an id to match...it doesn't even have to be the class name...it can be jibberrish, as long as both strings match. (This won't work the other way though...see next item)
  • When sending from Flex to php, AMFPHP will try to load the class with the name specified by the RemoteObject alias value. It simply looks in a specified directory to try and load the class...if it can't find it it's parsed as an array.

So, how does AMFPHP know where to look for the vo classes? Easy...you tell it exactly which directory to look in by setting the $voPath variable in globals.php. I usually do something along the lines of :

PHP:
  1. $voPath = $_SERVER["DOCUMENT_ROOT"]."/path/to/vo/directory";

Here's a more flushed out code sample:

Actionscript:
  1. package com.website.vos
  2. {
  3.     [RemoteClass(alias="Book")]
  4.     [Bindable]
  5.     public class Book
  6.     {
  7.        
  8.         public var title:String;
  9.         public var author:String;
  10.        
  11.         public function Book()
  12.         {
  13.         }
  14.        
  15.  
  16.     }
  17. }

PHP:
  1. <?php
  2.  
  3. class Book {
  4.  
  5.     var $_explicitType="Book";
  6.     var $title;
  7.     var $author;
  8.  
  9.  
  10. }

Say for example the Book.php class file is sitting on the server at webroot/php/classes/vos/Book.php. In order to tell AMFPHP where to look for the Book.php file, you open up globals.php in your AMFPHP installation, and set the $voPath variable to point to the 'vos' folder:

PHP:
  1. $voPath = $_SERVER["DOCUMENT_ROOT"]."/php/classes/vos";

Now when you send a Book object from Flex to php, AMFPHP will look in the $voPath (which we just set to the 'vos' folder) for the Book.php file.

Note that the $voPath variable is the starting point of where AMFPHP will start to look. If you specify a full package path for the RemoteClass alias, such as:

Actionscript:
  1. [RemoteClass(alias="com.website.vos.Book")]

then all the dots in the string are converted to slashes, and the full path is used. To continue with the example above, we have already set $voPath to point to the 'vos' folder, and the RemoteClass alias has been set to "com.website.vos.Book". AMFPHP converts the alias to "com/website/vos/Book" and will attempt to locate the file $voPath/com/website/vos/Book.php. In addition, if you're mapping this object from php back top Flex, remember the $_explicitType variable still must match the string for the RemoteClass alias, so you'd need to set that to:

PHP:
  1. var $_explicitType="com.website.vos.Book";

 Earthquake!

  • July 29th, 2008
  • 10:51 am

Just had a 5.8 magnitutude earthquake here in Los Angeles. Nothing too hairy, not enough to cause any damage, but still enough to get everything shaking pretty well.

 Flex MXML Code Formatting?

  • July 27th, 2008
  • 8:39 pm

Just throwing this question out there to pick the brains of other Flex developers: Do you have any preferences/standards that you follow for your mxml formatting? Care to share? Here are the formats I seem to come across most:

Single line, common attributes grouped together and listed first:

XML:
  1. <mx:Image id="thumb" x="10" y="20" width="90" height="90" scaleContent="false" source=""  />

Single line, with all attributes in alphabetical order:

XML:
  1. <mx:Image height="90"  id="thumb"  scaleContent="false" source="" width="90" x="10" y="20" />

Each attribute listed on a new line:

XML:
  1. <mx:Image
  2.     id="thumb"
  3.     x="10"
  4.     y="20"
  5.     width="90"
  6.     height="90"
  7.     scaleContent="false"
  8.     source="" 
  9.     />

Personally, I don't have a standard yet. I usually go with tags on a single line, but the attribues are in no particular order at all, except in pairs where it make sense, like x & y always together. I do go with each attribute on a single line for the opening tag of a component or the main Application, though...seems to make more sense to do it there.

 More Love For Charles

  • July 23rd, 2008
  • 10:54 am

If you're not using Charles, the awesome HTTP Proxy that lets you monitor your network traffic, you really should check it out. For me it's a must-have...the amount of time I saved debugging with it is ridiculous.

I just found out another totally awesome feature too..you can map remote directories to local directories. So say if you have a remote directory of www.blah.com/flash, you can tell charles to point that /flash directory to any directory on your local drive. Sweet!

 The Charges Against ActionScript 3.0

  • July 15th, 2008
  • 12:49 pm

Just finished reading the article "The Charges Against ActionScript 3.0" by Colin Moock. Interesting read, for sure. It echoes the same sentiments that I've been hearing from a few others lately...flash development is getting too cumbersome. I've heard way more groans along the lines of "it sucks that I have to learn actionscript to do the most basic things in flash anymore" as opposed to "I love AS3!". I think AS3 is great, but what drew me into Flash in the first place was how much I could get done quickly and easily, and that's certainly not the case anymore, being too far removed from it's point-and-click roots (the examples pointed out in the article sum this up perfectly).

Flex came about to get the "hardcore" developers, or at least the people who preferred to go the all-code route, their own separate workspace. However, many of the flash developers I know still have no interest in learning Flex. Hopefully Adobe will refocus on Flash IDE-centered development and rekindle that excitement of the earlier Flash releases.