Flex Project in IntelliJ with Charts

Posted by admin on May 30th, 2010

This year, my brother graduates as Civil Engineer. For his thesis, he needed a program that calculated the different criteria for building roads. Charts were ideal to show why certain materials were better and how they compared to each other. Starting from an Excel file, we first created the model, then implemented all the calculations and finished with creating tables and charts. Thanks to the help of my brother, we were able to create this application on short notice.

Normally I work with FlexBuilder, but for this project I wanted to experiment with IntelliJ. I already had experimented with BlazeDs in IntelliJ, but I had never really created a project. IntelliJ is great, but it’s really hard to compare it with FlexBuilder because the project I’m doing in FlexBuilder is way bigger. I would need to check FlashBuilder to be able to compare the features and import the big project in IntelliJ to see how compiling compares to each other.

The new Spark architecture was strange in the beginning, especially because now you have all these namespaces mixing together. Mx, s, fx, … I really should check some online resources and videos because now I just experimented while doing the project. Not a lot of time to go and search for things, best practices, …

No backend was used, but setting BlazeDs (or GraniteDs) up in IntelliJ is really a piece of cake. Coming from .NET world, it does feel strange and it’s a totally new world.

The project can be found here, but I think not a lot of people will understand it. There are three states: in the first general parameters need to be entered, in the second some specific parameters need to be entered and in the third all tables and charts are shown.

I still have one big problem and that’s loading the application. Apparently a couple of swf files are downloaded before the application is shown. I guess that these swf files should be included when compiling, but I haven’t managed to do this. If one of you knows how to resolve this, please let me know. Now the application is loading toooo slow. Maybe it’s a configuration in IntelliJ? I have searched online but haven’t found anything, so I guess it’s not a bug in Flex SDK 4.

<

WebBrowser Control – Flash DropDown Fix (Framework 2.0)

Posted by admin on May 4th, 2010

For a customer of ours we had to create a standalone browser that could load assessments for candidates. It couldn't be loaded in a browser because the user would have access to the computer. Anyway, the .NET WebBrowser component loads a html page with the swf that starts the assessment.
The problem now was that Flex/Flash dropdowns didn't seem to work. A candidate could click on the dropdown, the items were shown but when an item was clicked, the dropdown closed and the item was not selected. On my laptop I couldn't reproduce the bug.

After searching someone pointed me in the right direction on StackOverflow and with the help of this question on a vbdotnetforum, I finally managed to find the problem and two solutions.

Problem

It seems that when clicking the dropdown, a Flash layer is displayed on top of the dropdown with the items. At that moment, the WebBrowser seems to take over the focus. When clicking on an item, you are actually clicking on the whole Flash Application, giving back focus to the swf, but not selecting an item. Because Flash gets back the focus, the dropdown closes automatically.

Solution 1

The problem only occurs when the client pc has .NET Framework 2.0 installed and nothing higher. When installing .NET Framework 2.0 SP1 or 3.5, the problem is resolved.

Solution 2

By extending the WebBrowser component and overriding one function, you can resolve the problem without upgrading .NET Framework. Use this Class as your WebBrowser and everything should work fine (the VB implementation can be found at the link above):

C#:
  1. using System.Windows.Forms;
  2.  
  3. namespace SaltoExplorer
  4. {
  5.     /// <summary>
  6.     /// When clients have .NET Framework 2.0 installed and
  7.     /// nothing higher, then there's a problem that not item
  8.     /// can be selected in Flex DropDowns.
  9.     /// It's a problem with focus. From the moment
  10.     /// .NET Framework 2.0 SP1 or  higher (like 3.5) is installed,
  11.     /// the problem is resolved.
  12.     /// Extending the WebBrowser component can fix this problem,
  13.     /// but it should only be done if the problem occurs
  14.     /// (with .NET Framework 2.0)
  15.     /// See
  16.     /// http://www.vbdotnetforums.com/vb-net-general-discussion/18563-webbrowser-control-2-0-framework-flash-fix.html
  17.     /// http://stackoverflow.com/questions/2205924/problems-flashflex-in-net-webbrowser-component
  18.     /// </summary>
  19.     public class Edumatic3WebBrowser : WebBrowser
  20.     {
  21.         private const int WmLbuttondown = 0x201;
  22.         private const int WmRbuttondown = 0x204;
  23.         private const int WmMbuttondown = 0x207;
  24.         private const int WmMouseactivate = 0x21;
  25.  
  26.         private ContainerControl FindContainerControl()
  27.         {
  28.             ContainerControl cc = null;
  29.             Control ctl = this;
  30.             while(ctl != null)
  31.             {
  32.                 var tempCc = ctl as ContainerControl;
  33.                 if(tempCc != null)
  34.                 {
  35.                     cc = tempCc;
  36.                     break;
  37.                 }
  38.                 ctl = ctl.Parent;
  39.             }
  40.             return cc;
  41.         }
  42.  
  43.         protected override void WndProc(ref Message m)
  44.         {
  45.             switch (m.Msg)
  46.             {
  47.                 case WmLbuttondown:
  48.                 case WmRbuttondown:
  49.                 case WmMbuttondown:
  50.                 case WmMouseactivate:
  51.                     if(!DesignMode)
  52.                     {
  53.                         var cc = FindContainerControl();
  54.                         if(cc != null && cc.ActiveControl != this)
  55.                         {
  56.                             //Probably giving focus to the Swf
  57.                             cc.Focus();
  58.                         }
  59.                     }
  60.                     base.DefWndProc(ref m);
  61.                     break;
  62.                 default:
  63.                     base.DefWndProc(ref m);
  64.                     break;
  65.             }
  66.         }
  67.     }
  68. }

<

Educational software

Posted by admin on October 18th, 2009

I've been working almost 5 years now on educational software in two companies (first Indie Group, now Televic-Education). We mainly created CD-ROMS (that were enclosed with schoolbooks) and online solutions. All those applications were not built from scratch, instead we created a framework that could read in all exercises and hierarchy of the exercises. Those exercises were created in a back end were you could assemble them in folders and export them in a format for our framework (xml) or other formats like SCORM.

I haven't got any videos yet on those CD-ROMS, but you can see two of our online solutions in action. The first is Edumatic, the first application that was created and which has some 20 exercise types (multiple choice, fill in, cross word, dragndrop, translate, ...). It can be used online or exported to be used in CD-ROMS. On the site of edumatic, you can try out an online example of a multiple set of exercises (for each exercise type there are a lot of exercises). Our senior product manager (;-) Piet Santy) also shows an example each day created with Edumatic which you can follow on Twitter --> link. Please follow and try out his examples! Some of his past examples are shown here and here and here and here(demo). Edumatic back end is created in ASP.NET, the front end in Flash (AS2). Together with Christophe Herreman we created the framework for it, but a lot of other persons contributed to the framework, back end and exercise types like Kristof Neirynck(current technical lead), Bert Vandamme, Piet Santy, Sofie Deparcq and others.

Our other product, which is newer than Edumatic, is called Edumatic Exam. It is now used by three customers and has a lot of potential. It's more an assessment application than an exercise application and has currently some 15 exercise types. We are striving to support all exercise types from Edumatic, but that'll take some more time (we're nearly there). Client side is created in Flex, back end with .NET. This application is used by our government to test the knowledge of applicants. Daily there are multiple sessions with hundreds of candidates. We haven't got a demo online yet, but if you subscribe yourself at Selor, you can practice some of the language assessments with our application (you need to go to Mijn Selor, subscribe and then choose Taaloefenpakket... all in Dutch or French...) Try it out! The product is also online, but currently you can not register for it. That'll be something for the future. Currently working most on Edumatic Exam are Bert Vandamme, Sem Dendoncker, Wouter Vanden Berghe and me.

Cheers and practice!

<

Creating new components in Flex 3

Posted by admin on April 14th, 2009

Recently I saw a screencast from Deepa Subramaniam at Max2008 on how to create new components in Flex 3 (link). I would urge everybody to watch this video if you're not familiar with this topic.

Something I noticed in this video was the use of Bindable metadata tag with event name specified. If you make a setter Bindable, then it's kinda of a performance loss to trigger the binding if the new value that's being set is the same as the old value. Here's a way to improve this:

Actionscript:
  1. [Bindable(event="xChanged")]
  2. public function get x():Number{ return _x; }
  3. public function set x(value:Number):void{
  4. if(_x != value){
  5. ...
  6. dispatchEvent(new Event("xChanged"));
  7. }
  8. }

<

Flex Data Binding expressions and Arrays

Posted by admin on April 14th, 2009

Last week I searched a little on a problem with bindings in Flex. Seemed like I couldn't add a binding to an Array. After a question on Stack someone gave me the answer. Apparently it is well documented in the Flex 3 help (link)

Quote:

When defining a data binding expression that uses an array as the source of a data binding expression, the array should be of type ArrayCollection because the ArrayCollection class dispatches an event when the array or the array elements change to trigger data binding. For example, a call to ArrayCollection.addItem(), ArrayCollection.addItemAt(), ArrayCollection.removeItem(), and ArrayCollection.removeItemAt() all trigger data binding.

<

Memento Pattern

Posted by admin on April 11th, 2009

Yesterday I tried to implement Undo functionality with Command Patterns. The Memento pattern can also be used to do this. So what is the difference between the two?

Well, with Memento pattern the state of an object (the originator) is being stored by a Caretaker class. So if it's possible to Undo with returning back to a previous state, use Memento pattern. Sometimes however, the originator is too complex to save each time its state (it could be a composite for instance). In that case the undo facility can use commands. Whenever an action is received a compensating action is set up and stored in the undo facility.

Example in Flex of Memento Pattern. I haven't added too much comments because the code and example should speak for itself.

thx, Lieven Cardoen

Related: Command Pattern Undo Functionality

<

Pattern for Undo functionality

Posted by admin on April 10th, 2009

Yesterday someone asked me how to implement Undo functionality.  I knew there was a pattern commonly used for this, but couldn't remember it. In my common sense I would keep track of previous states of properties (or actions). After some search I found that Command pattern is a good choice to implement the Undo functionality.

With some online examples I implemented an undo functionality pattern in Flex. Doing such an exercise makes me understand the theory behind it better.

Here's the first example. Right click on the swf to view the source.

Next is implementing redo functionality in it. In a third step I'll try to make some things more generic so I can use it easily in our product.

What would also be interesting is to make the example work in a way that only whole words are undone instead of single characters. I'll also look into that later on.

thx, Lieven Cardoen

Related: Memento Pattern

<

Allow Port on Windows Server to enable WebORB Messaging

Posted by admin on March 6th, 2009

Had a problem starting the WebORB RTMPServer (in global.asax) today which was solved after adding the port as an exception in the Windows FireWall.

Log from WebORB:

[Thread-11] WEBORB INFO:6/03/2009 11:26:37:shutting down WebORB Message Server
[Thread-11] WEBORB EXCEPTION:6/03/2009 11:26:37:System.Net.Sockets.SocketException: A request to send or receive data was disallowed because the socket is not connected and (when sending on a datagram socket using a sendto call) no address was supplied
at System.Net.Sockets.Socket.Shutdown(SocketShutdown how)
at Weborb.Messaging.RTMPServer.shutdown()
[Thread-15] WEBORB EXCEPTION:6/03/2009 11:26:37:System.Net.Sockets.SocketException: A blocking operation was interrupted by a call to WSACancelBlockingCall
at System.Net.Sockets.Socket.Accept()
at Weborb.Messaging.RTMPServer.run()
[Thread-11] WEBORB EXCEPTION:6/03/2009 11:26:37:System.ObjectDisposedException: Cannot access a disposed object.
Object name: 'System.Net.Sockets.Socket'.
at System.Net.Sockets.Socket.Disconnect(Boolean reuseSocket)
at Weborb.Messaging.RTMPServer.shutdown()

Adding an exception in windows firewall is done in the "Windows FireWall Settings". Choose tab Exceptions and Add port... There you enter the port that you use for the RTMPServer (default 2037), give a name and choose TCP.

thx, Lieven Cardoen

<

Peformance issues IIS7, WebORB, Network, …

Posted by admin on February 21st, 2009

Two weeks ago I had a lot of problems in a project of mine. Often some clients couldn't connect to weborb.aspx (actually 0.01% of the times). After a lot of searching we weren't really able to find the problem. It seemed to me that maybe it was a network issue. The customer had just changed a lot of servers and improved their network. What previously worked didn't seem to work anymore now.

We changed some things after which everything started to work smoothly again:

- When an error is thrown from the server or there's a network problem we invoke the server call again with Credentials. We use authentication, so if at a certain moment in time IIS decides to recycle, the next calls to the server will fail. So we implemented a fallback system. If a fault occurs we authenticate again and try the call a second time. If the second time would also fail, then we give the user an Alert with some information what to do.

- When profiling SQLServer2008 we saw that there were millions of logs being written to the database by WebORB. We had configured WebORB logging with Log4Net and set the Filter in Log4Net on INFO. Basically everything that was logged was written to the database. This meant a lot of overhead. After having put the Filter on Warning connections to database reduced by a factor 100.

Configuring WebORB Logging with Log4Net (in global.asax):

C#:
  1. void Application_Start(object sender, EventArgs e)
  2.     {
  3.         log4net.Config.XmlConfigurator.Configure();
  4.         log4net.ILog log = log4net.LogManager.GetLogger("Global.asax");
  5.         log.Info("Application_Start(" + sender.ToString() + ", " + e.ToString() + ")");
  6.  
  7.         //Configuring WebORB Logging with Log4Net
  8.     try
  9.     {
  10.         Weborb.Util.Logging.Log.addLogger("log4NetLogger", new Edu3.Util.Logger())
  11.                 Weborb.Util.Logging.Log.removeLogger("default");
  12.     }
  13.     catch (Exception exception)
  14.     {
  15.         log.Error("Application_Start", exception);
  16.     }
  17.     }

- We profiled IIS7 with some tools that were proposed on StackOverflow. These tools were very interesting, but still I thought to get much more information. Strange that there's not a professional profiling tool for IIS7. We used Administration Pack for IIS 7.0, the stackoverflow question is at link. The strange thing was that in 0.01% of the requests a 404 was returned. Even after having enabled Failed Request Tracing in IIS7, I couldn't find the reason for the 404.

- Recycling happens automatically @ 23 hours. (this was allready done earlier when I had problems in November).

After these tweaks everything is working fine again. Those 404's remain a mystery...

Ciao, Lieven Cardoen

<

AS3 – C# String Replace with Regular Expressions and Callback function

Posted by admin on January 15th, 2009

In AS3:

Actionscript:
  1. ...
  2. var regExpDigitString:String = "\\d+"
  3. modified = original.replace(new RegExp(regExpDigitString, "gi"), findSuffix);
  4. ...
  5.  
  6. private function findSuffix():String {       
  7.     var result:String = arguments[0];
  8.     var index:int = arguments[1];
  9.     var input:String = arguments[2];
  10.        
  11.     ...
  12.                
  13.     return result;
  14. }

In C#

C#:
  1. ...
  2. String regExpDigitString = "\\d+";        
  3. modified = Regex.Replace(original, regExpDigitString, new MatchEvaluator(findSuffix), RegexOptions.IgnoreCase);
  4. ...
  5.  
  6. private String findSuffix(Match m) {
  7.     String result = m.ToString();
  8.     int index = m.Index;
  9.     String input = original; //apparently you can't get the original string out of the Mach Object, so you'll need a reference to the original Object in your class.       
  10.            
  11.        ...   
  12.  
  13.     return result;
  14. }

<

Copyright © 2007 Johlero – Cardoen Lieven. All rights reserved.