SubClosure

{ Don't Repeat Yourself ! }

FlexUnit Setup

No comments

Required steps to integrate FlexUnit into a Flex project
Just some reminder notes to set up Flex unit testing. These are valid for FlexUnit 0.9

1. copy the FlexUnit.swc to the projects libs folder

2. Create unit tests
Each Unit test is a simple Actionscript class that extends TestCase

public class MyTest extends TestCase

It contains a number of functions where the function name must start with a test
e.g. testFunc

Each function contains a number of assertions methods.
There are several assertion methods available for our unit tests such as:
assertTrue, assertFalse, assertNull, assertEquals, and several others.

3. Create a new MXML Application

add this mxml tag to the application

<flexunit:TestRunnerBase id=”testRunner” width=”100%” height=”100%” />

add these lines to a creationComplete handler function:

testRunner.test = createSuite();
testRunner.startTest();

add these lines to the createSuite function

var testSuite:TestSuite = new TestSuite();
testSuite.addTestSuite( MyTest );
return testSuite;

all done run the test application and watch it fail

I recently purchased a Mac Book Pro – primarily for software development. As a long time Linux and Windows user I though it would be time to try something new and join the hype.

To work with Mac OS efficiently I needed to install quite a bit free extra software.
Here is a list of what I found useful for my purposes.

Awesome and free:

  • Firefox – I like it much better then safari
  • Perian – adds support for many popular video formats such as divX
  • Open Office – used this under Linux and Window as well
  • Google Notifier – check for new Google Mail and Google Calendar entries
  • Google quick search box – search for anything from your taskbar
  • iChat with Google Talk – use iChat to chat with your google buddies
  • Virtual Box – free virtual machine to run Windows or any other OS
  • Skype – I use skype since many years to stay in touch and do my calls
  • Seashore – easy to install free image editor based on gimp

Free development tools:

  • Xampp – save yourself the hassle of setting up Apache, Mysql, PHP, etc
  • Eclipse – my favorite development platform
  • jEdit – a free editor for programmers, written in java
  • Cyberduck – handy opersource ftp, sftp, webdav browser for Mac OS X
  • Wget – Mac OS X only comes with curl. But curl does not provide the same functionality as wget
  • NVU – NVU is a handy and free HTML and CSS Editor
  • Free Ruler – measure things on your screen with this useful little tool

Commercial Tools:

  • Path Finder – replacement for mac finder with great features like tabs and split pane

A cool website listing all opensource mac applications

I have recently found an awesome thread on software comments.

It made me laugh out loud a few times, even though I was in a very bad mood that day.

Some of these comments are just hilarious. Sooo funny.

Check it out

http://stackoverflow.com/questions/184618/what-is-the-best-comment-in-source-code-you-have-ever-encountered

As always with flex, the most simple problems are the hardest ones to solve.

For example to get FileReference to download a file from the server.

now you would think that creating a URLRequest followed by a simple call to the FileReference's download() function should do the trick.

But think again cause that results in  no error and no download either.
The save dialog shows up and then … nothing … NICE

Now the solution is very simple:

just declare your FileReference instance as a class variable, outside of the function from where you use it.

And boom it magically works.

Another nice undocumented flex feature that can cost a bit of hair-loss and some
time spend in a mental hospital.

lucky are those who use FileReference as a class variable from the beginning.

In order to use a label as a button, the following parameters should be set

useHandCursor="true"
buttonMode="true"

and

mouseChildren=”false”

Joomla is a great CMS – one bad thing about it – the documentation just sucks.

I have recently been using Zend AMF with Joomla in a custom component to communicate with a Flex Application.

To get the output back with the right content-type headers you need to
add the following before you return the amf content.

$document =& JFactory::getDocument();
$document->setMimeEncoding(‘application/x-amf‘) ;

If you dont do that it might still work, but you wont be able to see any debugging information in Service Capture for instance.

Flex itself seems to be clever enough to decode even a text content type properly.

I ran into issues with Flex Itemrenderers after applying custom styles to a Datagrid.

Displaying the data in a standard Datagrid Column worked fine, such as:

<mx:DataGridColumn headerText="First Name" dataField="firstName" >

But an itemrenderer component just ignored all style declarations.

All I wanted to achieve is having my itemrenderer using the same text color and
textSelectedColor as I declared for the DataGrid in my css file.

After a bit of research I found a solution that works.

In order to use some declared styles from the ListBase (in my case the Datagrid) in my
custom itemrenderer I had to override its updateDisplayList Method.

My inline itemrenderer now looks like this

<mx:itemRenderer>

<mx:Component>

<mx:VBox>
<mx:Script><![CDATA[
import mx.controls.listClasses.ListBase;
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight )  ;
if(owner is ListBase) {
if(ListBase(owner).isItemSelected(data) ) {

setStyle(“color”, ListBase(owner).getStyle(“textSelectedColor”) );

}

else {

setStyle(“color”, ListBase(owner).getStyle(“color”) );

}

}

}

]]></mx:Script>

<mx:Label
text=”{data.firstName}” />

<mx:Label
text=”{data.lastName}” />

</mx:VBox>

</mx:Component>

</mx:itemRenderer>

Now this seems all a bit weird cause it has to be done for each itemrenderer and each style that needs to be applied.
But it is the only quick solution I could find so far.

Note:
If using the Advanced Datagrid you need to change ListBase to:

mx.controls.listClasses.AdvancedListBase

for this example to work.

I recently needed to replace all  Degree ( ° )  symbols with a dot ( . ) symbol in a String.

So I tried this: $result = str_replace("°" , "." , $mystr) ;

It did not work, because the String ($mystr) was encoded in UTF8, since it was read in from a file.
PHP could not properly compare the characters.

I fixed it by changing the default encoding of my string:
$mystr = utf8_encode  ( $mystr) ;

After that the str_replace function returned the expected result.

It seems to be a good idea to always declare the encoding when loading local or remote files in PHP.

Mate Templates

No comments

Some Mate notes:

  • When using AsyncMethodInvoker, use the currentEvent  property instead of event to get the right property

In order to view and edit Mantis Tasks directly from Eclipse or Flex Builder
you need to install the Mylyn Plugin for eclipse first:

http://www.eclipse.org/mylyn/

Then install the Mylyn – Mantis Connector:

https://github.com/Mylyn-Mantis/mylyn-mantis

To add your mantis repository click on Window->Other Views in Eclipse.
Select the Mylyn Folder and add task list and task repositories.

Then go to the task repository view, right click and choose to add a new repository.

Now the trick is to enter the right URL to your Mantis service file.
Its normally found under http://yourdomain.com/mantis/api/soap/mantisconnect.php (since mantis 1.1.0)

If that’s done you can add a query by choosing a project and a filter (needs to be set up on the mantis web interface first) .

Now you can view and change your mantis tasks in the task view.

Get Adobe Flash player