February 3, 2010

Custom Eclipse Style XCode shortcuts

Filed under: Flex, XCode tips, iphone — Anthony @ 11:52 pm

After using eclipse for so long i have become a custom to my shortcuts and xcode just doesn't stand up to the job as far as i am concerned so here is a small list of the custom key bindings i have setup for myself. I will add more as I create them.

To create a custom key bindings file goto XCode>Preferences>Bindings> Duplicate an existing binding and name it whatever you want then go to and open the file you just created in a text editor so you can see the xml output.

~/Library/Application Support/Xcode/Key Bindings/*.pbxkeys

A good list of available commands can be found here

1. Duplicate code!

I can't believe xcode doesn't have this in Eclipse you simple select your text and press Ctrl + Alt and either Up or Down on the keypad and it will duplicate your code placing it either above or below the current selection. It will also reselect the newly duplicated code so that you can duplicate it as many times as you like.

<key>^~\U700</key>
<array>
<string>copy:</string>
<string>moveUp:</string>
<string>moveToEndOfLine:</string>
<string>insertLineBreak:</string>
<string>insertNewLine:</string>
<string>setMark:</string>
<string>paste:</string>
<string>selectToMark:</string>
</array>
<key>^~\U701</key>
<array>
<string>copy:</string>
<string>moveDown:</string>
<string>moveToBeginningOfLine:</string>
<string>insertLineBreak:</string>
<string>insertNewLine:</string>
<string>moveUp:</string>
<string>setMark:</string>
<string>paste:</string>
<string>selectToMark:</string>
</array>
2. Delete Line.
Deletes the current line your cursor is on. press Ctrl + D.
<key>^d</key>
<array>
<string>cut:</string>
<string>selectLine:</string>
<string>cut:</string>
</array>
January 10, 2010

Iphone Development course

Filed under: iphone — Anthony @ 8:42 pm

I have been meaning to start building an iphone application for some time now and recently stumbled across Stanfords CS193p iphone development course on ITunes U I have found it really useful especially the Assignments. more...

December 30, 2009

Installing Japanese, Chinese or even Korean on UK Blackberry

Filed under: Japanese — Anthony @ 3:48 am

Just in case anyone was having as much trouble as me installing one of the above languages onto their UK Blackberry I thought i would post this very useful link.

http://www.blackberryforums.com/general-8300-series-discussion-curve/151613-cjk-support-os-4-5-a.html

November 16, 2009

Forcing Firefox to open Flex in the same window

Filed under: Flex — Anthony @ 10:44 am

Using FireFox as your main browser when developing on Windows means that by default you end up getting loads of tabs for all your canceled debug sessions. In order to prevent this behavior simply type in
about:config
into the address bar and do a search for
browser.link.open_external
then change it's value from 3 to 1; this will make your flex debug session always appear in one tab.

October 16, 2009

Binary Clock

Filed under: ActionScript, Personal, experiments — Anthony @ 11:56 pm

I have been looking into bits, bytes and bit shifting a lot recently so I thought I would quickly make a small binary clock to help burn it into my mind. In addition it also gave me the chance to experiment with the spark skinning. Below is the result. Not pretty I know but thats what the skinning is for.

Get Adobe Flash player

Full source

October 14, 2009

Code Optimization tricks

Filed under: Flex — Anthony @ 9:03 am

Collapse literal values

 
  var a : uint = b + ( 10024-200 ) / 2;//195msvar a : uint = b + 412;//47ms
 

Multiplication is faster than Division
nice explanation of using multiplication for division here

 
  result = num / 4;//382ms
√ result = num * 0.25;//132ms
 

Use Implicit type casting

 
  var a : Point = points[ i ] as Point;//179msvar a : Point = points[ i ];//109ms
 

Test variables before methods in statements

 
  if(method( ) && variable )//211msif( variable && method() )//7ms
 

Declare varialbes outside of loops

 
for( var i : int = 0; i < arr.length; i ++ )//515ms
  var i : int = 0;
  var arrLength : int = arr.length;
√ for( ; i < arr.length; i ++ )//39ms
 

Thowing erors takes time.

 
  try{ isNull.x = 3; }catch( e : Error ){ }//78msif( isNull ) { isNull.x = 3; }//0ms
 

Use references instead of full paths or the with operator.

 
  with( sprite.graphics ){ ...};//164msvar g : Graphics = sprite.graphics;//23ms
 

Use Object Pools

Bitwise tricks
Bitwise maths on wikipedia Boolean algebra on wikipedia
polygonal labs bitwise gems

 
val = num | 0; //Same as Math.floor();
val = num + 0.5 | 0; // Rounds positive numbers.
//Divide by power of two
val = num >>1; //Divide by 2 and floor.
val = num / 32 is the same as val = num >> 5
val = 65535 >> 8; //255
//actual value is 255.996...
//But it is being floored as well
i = (x^(x>>31)) - (x>>31);//about 2700% faster than Maths.abs();
 
if(++count&1){}//alternation i need to check this one.
 
September 28, 2009

Forcing the Browser to crash using ActionScript

Filed under: ActionScript, Flex — Anthony @ 11:59 pm

I just discovered this little trick, I'm not sure how useful it is but it works.

Simply create a class that throws an error in the constructor. This will cause the browser to crash and close.

 
 
package
{
   public class BrowserCrasher
   {
      public function BrowserCrasher( )
      {
         throw new Error( 'goodbye browser' );
      }
   }
}
 

Enums and static initializers in AS3

Filed under: ActionScript, OOP — Anthony @ 10:24 pm

I just came across the idea of static initializers in Java and was wondering if they are available in ActionScript as well.

I found a couple posts on the subject.

post 1

post 2

August 19, 2009

Getting snippets to work with FlashBuilder Beta

Filed under: Flex — Anthony @ 10:40 am

Just a quick note here. I use the excellent snippet plugin from Lee Brimlow over at the theFlashBlog so that i don't have to put up with all the cfeclipse icons across the top of my toolbar. But I recently installed a beta version of FlashBuilder and found that when i installed the plugin it would no longer work. After much searching i found the solution for me was to go into the plugin folder and open the META-INF/MANIFEST.MF file and remove the following two lines from the bottom of the file.

org.eclipse.jface.text;bundle-version="3.4.1",
com.adobe.flexbuilder.editors.common;bundle-version="3.0.214193"

This re-enabled the plugin for me. Great!

Another little tip with working with snippets and workspaces:
when switching workspaces you lose all your snippets as they are kept in the workspaces .metadata/.plugins/org.cfeclipse.cfml/snippets
this folder is recreated for each new workspace you create. So what i do is keep a global snippets folder in my main workspace and simply replace the snippets folder in my other workspaces with a simlink to the main one. That way when ever i add a new snippet it is shared across all my workspaces.

just a little side note:: if you don't know how to show hidden files in mac osx. type the following into the terminal and then restart finder.

defaults write com.apple.Finder AppleShowAllFIles TRUE

To turn it off set it to false. You also need to restart Finder for it to take effect.
Also if you don't know how to create the simlink you simple go into the terminal, navigate to your workspace then .metadata>.plugins>org.cfeclipse.cfml delete the snippets folder that is in there and then type
ln -s PATH TO YOUR WORKSPACE WHERE YOU KEEP YOUR MAIN SNIPPET FOLDER/snippets Snippets

This should then put a simlink inside your workspace and you can then share your snippets across all your workspaces instead of having to copy them into each.

August 18, 2009

IMXMLObject for non visual components

Filed under: Flex — Anthony @ 11:34 am

I have been using Flex for a couple of years now and i still find new and interesting framework items. In comes IMXMLObject. Up until recently whenever i wanted to place a non visual component into mxml i was extending UIComponent to allow me to place these items in MXML, however among other things this meant that they would be included in the layout and come with a high footprint.
The solution seems to be to implement the IMXMLObject interface this will allow you to place non visual components into your mxml code without having to worry about layout or an unnecessary memory footprint.

usefull links
livedocs
smashedapples
techper