SubClosure

{ Don't Repeat Yourself ! }

Browsing Posts in Flex

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

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.

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