February 3, 2010
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>
November 16, 2009
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 14, 2009
Collapse literal values
var a : uint = b + ( 10024-200 ) / 2;//195ms
√ var 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;//179ms
√ var a : Point = points[ i ];//109ms
Test variables before methods in statements
if(method( ) && variable )//211ms
√ if( 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 ){ }//78ms
√ if( isNull ) { isNull.x = 3; }//0ms
Use references instead of full paths or the with operator.
with( sprite.graphics ){ ...};//164ms
√ var 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
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' );
}
}
}
August 19, 2009
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
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
July 17, 2009
I recently discovered that data binding doesn't work with Vectors in Flash Builder. I have reported a bug at the
adobe bug base you can read more about the issue
here
July 8, 2009
I was strolling through the UIComponent source code earlier today when i cam across this line of code.
//--------------------------------------------------------------------------
//
// Class mixins
//
//--------------------------------------------------------------------------
/**
* @private
* Placeholder for mixin by UIComponentAccImpl.
*/
mx_internal static var createAccessibilityImplementation:Function;
I wasn't entirely sure what a mixin was but after reading up on wikipedia I realized they are exactly what they sound like basically just a mix of code bases. There is a really good post over on the yahoo flash blog about accessibility and the way in which Flex uses the
[AccessibilityClass(implementation="mx.accessibility.UIComponentAccImpl")]
meta data to mixin the Accessibility code into the UIComponent implementation.
April 29, 2009
I just wanted everyone to know about
this awesome class i found. I needed to load some Flash 8 movies into my flex application and control the play head dependent on labels inside the flash movie.
This was proving really hard until i found that class now it is a piece of cake!
Thanks whoever you are maruthi2000
March 18, 2009
I was trying to load a byteArray into an image control today and would randomly get an Unhandled IOErrorEvent message. Now this shouldn't really happen as the image control uses a default broken image icon to display when there are any loading problems. Well after trying to catch the error unsuccessfully I wanted to know what was going on.
So i went digging and i found in the base class of image, SWFLoader line 1497 the following
(more...)