Ubacoda.com is an independant developer of mobile applications. Welcome to the ubacoda.com blog!

Firebug Debugging in TextMate

Mon Nov 16 12:13:56 2009

I do almost all of my coding in what I believe is the best text editor currently on the planet, and the best thing since sliced bread - TextMate.

It is so light, has the best features, including live preview and snippets, and can now be used to debug code such as JavaScript, PHP and even ActionScript 3 through Mozilla's Firebug

There are a lot of hacks and plug-ins around that allow you to debug in various ways, including as-you-type Terminal output, which is very cool indeed but something I will leave for another post. The method of debugging JavaScript that I am most impressed with so far is DocTyper's Firebug bundle for TextMate. You can get a copy here along with some more detail on the subject. But for now, just check it out and don't forget to turn on "Enable access for assistive devices inside "Universal Access" on the Mac System Preferences panel.

For ActionScript, check out the Flashbug extension of Firebug, which you can find by doing a simple search on the Mozilla Addons page. You will also need a copy of the Debug Flash Player which you can of course download from the Adobe Flash Player Downloads page. Next create a file called mm.cfg and place it in Library/Application Support/Macromedia/(file goes here), and then add the following lines of text to it and save.

TraceOutputFileEnable=1
ErrorReportingEnable=1

A file called Flashlog.txt will automatically be created in the directory Users/(your name)/Library/Preferences/Macromedia/Flash Player/Logs/(Flashlog.txt file found here) FlashBug will read from this file and display any trace statements inside FireFox, which I personally find very helpful.

As a quick side note, I just want to add that ActionScript people might also want to try and Google Sephiroth Flash Tracer extension for FireFox. If you aren't using FireFox you may want to check out Vizzy Flash Tracer which is a standalone tracer.

Anyway, that's all for now, so get debugging those applications!

AS3 Simple Grids

Sat Nov 14 16:16:16 2009

I have decided to share a class with you that I recently developed for an ActionScript project that required a grid layout of MovieClips. Making grids in AS3 isn't really that difficult, but the class I've developed will save me a lot of typing and since building grid layouts is something that I may do a lot more of in future projects it seemed like a sensible thing to do.

It is quite a simple class but may come in handy from time to time. Please feel free to edit the code and do as you will. It's usage is simple. Just import it, create however many instances of an object you want to have in your grid, and apply the public static function createGrid(); from the Grid class. In the example grid below I used dark grey, 40 x 40 px MovieClips

Get Adobe Flash player

Grid.createGrid(); The parameters are (1:StageObject, 2:Array, 3:{Object})

Instructions of Use

1. The StageObject is simple. Just pass the stage of the first MovieClip your are throwing inside the grid. This will give us the ability to call the public static method without instancing the class itself, which I always find beneficial and try to do when I can.

2. The Array should be an array of all the names of the objects you want to place inside the grid. Objects will be ordered in the same order as they are placed inside this Array.

3. The Object can contain any of the 4 options available, which include col, spaceX, spaceY, and centered. col receives a Number and defines the number of columns the grid should have. spaceX and spaceY also receive a Number and respectively control the vertical and horizontal spacing between each object inside the grid. In other words, they control how big the gaps are inside the grid. The final parameter center:Boolean gives the option to offset the grid to the right by half the width of each instance fed into the array, so that the grid appears centered. If no parameters are given (Note* curly brackets are required {} even without parameters), the grid will set to a default of a non-centered, 6-columns grid with 10px vertical and horizontal spacing

Example Code

Grid.createGrid(this, nameArr, {cols:10, spaceX:10, spaceY:10, centered:false} );

For more info, just take a look at the fully annotated example files I've set up. They can be downloaded here

I would love to hear your opinions about this, but since I don't normally share my code, please be gentle with any criticisms. If you would like to host this code on your own website, please make sure to credit back to yours truly. Happy grid making!

New Apple Magic Mouse

Fri Nov 6 00:18:04 2009

I have to admit that I am a very big fan of Apple. Anyone who owns an Apple computer will probably comment on how reliable they are. However, with that said, I have to confess that I never really been impressed by the quality of Apple mouse technology.

About a year ago, I procured with great delight an Apple 'Mighty Mouse'. At the time, I was using Illustrator an awful lot and the 360 degree scroll ability of the Mighty Mouse was very desirable. However, now I have to say it is a constant battle trying to keep the scroll-ball working. Sending it to Apple for a clean every few months (maybe more often) just to have it scroll again would be an immense pain in the proverbial backside, and taking it apart to clean those little roller things inside time after time just to have it cease up on you again is tiresome, time consuming and down right infuriating, especially considering the price one costs. Let's face it, Apple products aren't cheap and you would expect them to do what it says on the tin.

With the new Apple Magic Mouse it looks as though Apple has realized their mistake and have completely got rid of the scroll-ball design. The Magic Mouse will interpret user input such as swipe and scroll actions reminiscent of the Apple iPhone, which although gimmicky, will surprisingly shave import seconds off your user experience.

If and when I come around to purchasing one, I will undoubtedly write a review here. Until then you can find more info at the Apple Magic Mouse webpage

Remove Spaces in PHP Strings

Mon Oct 26 01:07:57 2009

I'm still very much at the beginning of learning PHP and while programming this blog, I came across a wonderful PHP function that can be used to remove/replace spaces (amongst other things) in strings. I know it will come in handy for someone. It's called str_replace(); The syntax is as follows:

str_replace(item to be replaced, item to replace with, string to commit this function);
<?php	
 
//creating a string held inside a variable.
$origString = "This is the original string.";
//display the string.
echo $origString;

//replace " " width "". In other words, replace spaces with no spaces.
$newString = str_replace (" ", "", $origString);
//display the new string.
echo $newString;

?>

Counting PHP Array Repetitions

Sat Oct 17 04:07:54 2009

The ability to check an array in php and see if the items it contains reoccur somewhere else inside the array is something that comes in handy once in a while. If for example, you have a list of dates and you wanted to count how many times the same date reoccurs in the array and display the results, this is what you would do.

<?php
 $arrayToCount = array("1981","1973","2010","1973","1981","1973");

 foreach( $arrayToCount as $val ) {
   if ( array_key_exists( $val, $arrayCounter) ) { 
      $arrayCounter[$val]++; 
   }
   else { 
      $arrayCounter[$val] = 1;
   }
 }
	
 while( $element = each( $arrayCounter ) ){
 echo $element[ 'key' ].' ('.$element[ 'value' ].')';
}
?>

As is, the results of this would look like this

1981 (2)
1973 (3)
2010 (1)

Here's what's happening. Obviously, we have an array containing dates that we want to count shown on line 1. We use a foreach loop to run the contents of the loop for however many dates are contained inside the array. An if/else statement is used on line 4 through 9, which uses the PHP function array_key_exists()(line 4.), which checks to see if $val (the date being checked) matches a value previously looped through. If this function returns true the value inside $arrayCounter gets pushed up by 1 or ++ each time (see line 5). If the array_key_exists() on line 4 returns false, or in other words, no match is found, then the value 1 gets added to a new place in the $arrayCounter array. We then use a while statement to display each of the dates and their count values stored inside the associative array $arrayCounter(lines 12 ~ 14)

And that's about it. If you are new to PHP, I would recommend drilling this kinds of routine into your head and you'll get your head around it before you know it.

Most recent posts

  1. Flashcards Maker - the app the helps you learn in a flash
  2. Convert Font Suitcase to TTF in 3 Easy Steps
  3. Rain or Shine - Weather Forecast Available Now!
  4. Getting around Apple's silly rules for iOS 10
  5. Localising App Names for iOS and Android

Search site:

Apps by Ubacoda.com

Click the app icons to see more info


Archives

Categories