Archive for the ‘Flex’ Category

Parsley 2 + Spicelib - simple MVC Flex example

Sunday, October 11th, 2009

The new release of Cairngorm 3 beta was a good news for me but after a quick study about Cairngorm 3 I have found that several of the Cairngorm 3 libraries are implemented as extensions to the Parsley Application Framework

Because I am a very curios guy I have read a little more about Parsley Application Framework and I have to say that Jens Halm made a very good job with this framework. Parsley Framework offers you a lot of flexibility and the framework is easy to extend. Some of the cool features of the framework are :

  • Dependency Injection
  • Messaging ( this is my favorite )
  • Flex Modules support
  • Localization

Parsley Framework is good documented but I have not found a good and simple example of using Parsley. So I decided to write this article and post a simple example that can help you to understand how to create a MVC application using Parsley .

You can see the application down (username: admin, password: admin )

If you have any questions post them here.

View the exampleView Source

A Custom Drag-n-Drop List Control for Flex

Sunday, April 12th, 2009

Recently I have work on a custom component that extend the List class and add more functionalities to that class.The class do a lot of stuff but I decided to write a simple example for the blog that show just one functionality. The problem that this example solve is very simple:

“Make a list control that allow to drag only some of the list items”

The final result looks like this:

 

The steps to this are:

1) Create a list control and enable drag and drop

<mx:List
        id=”plList”
        width=”300″
        height=”300″
        dragEnabled=”true”
        dragMoveEnabled=”true”
        dropEnabled=”true”
        dragOver=”listDragOverHandler(event)” />

2) Create a XML that we will use as a dataProvider

<mx:XML id=”playlists”>
     <root>
          <pl name=”Playlist1″ icon=”myIcon” canMove=”1″ />
          <pl name=”Radio” icon=”myIcon2″ canMove=”0″ />
          <pl name=”Random” icon=”myIcon” canMove=”1″ />
          <pl name=”Best 90″ icon=”myIcon” canMove=”1″ />
          <pl name=”Custom” icon=”myIcon2″ canMove=”0″ />
     </root>
</mx:XML>

if you look at the XML you will see that a playlist contains 3 attributes. The name, icon and canMove. The canMove is the important attribute for us because this attribut will tell us if a item can move or not. Now that we have the XML let’s tell our list that we want to use this XML as a dataProvider and the name attribute as label:

<mx:List
        id=”usersList”
        width=”300″
        height=”300″
        dragEnabled=”true”
        labelField=”@name”
        iconField=”@icon”
        dataProvider=”{playlists.pl}”
        dragMoveEnabled=”true”
        dropEnabled=”true”
        dragOver=”listDragOverHandler(event)” />

3) Create a function that will be called when a list item is drag

private function listDragOverHandler( event:DragEvent ):void
{
        // with this call we are telling that we will
        // handle the drag
        event.preventDefault();

        // check to see if selected item can move
        var selectedItem :XML = XML(plList.selectedItem);
        var move :Number = Number(selectedItem.attribute(’canMove’));

        // if drag item can move
        if (event.dragSource.hasFormat(”items”) && move)
        {
                // Drag allowed
                event.currentTarget.showDropFeedback(event);
                DragManager.showFeedback(DragManager.MOVE);

                return;
        }

        // Drag not allowed.
        event.currentTarget.hideDropFeedback(event);
        DragManager.showFeedback(DragManager.NONE);
}

And this is all. If you have any questions post them here.

View the exampleView Source

Flex Builder Cannot Locate the Required Version of Flash Player

Saturday, March 28th, 2009

I am writing this post becouse I am very “angry” and I need to say something before I explode. This error has “eat” three hours of my time (I am very angry when I lose my time with useless things).

All starts with a fresh OS. After I have install Adobe Flex Builder and import some of my projects I had try to run one project in a stand alone Flash Player BUT (big buttt) I have receive :

Flex Builder Cannot Locate the Required Version of Flash Player” .

This was not my first time when I have receive this error so I had try to fix this, the simplest way I had know, access http://www.adobe.com/support/flashplayer/downloads.html download Flash Player 10 ActiveX control content debugger and reinstall Flash Player, BUT (again big buttt) no result the Flex Builder still bother me with : ”Flex Builder Cannot Locate the Required Version of Flash Player” so I call my best friend “Google” asking him about the error.

After at least a hour of searching and reading all I have found was how to fix this error for Firefox:

Firefox was looking for the npswf32.dll in the ProgramFiles/Mozilla Fireforx/plugins directory yet Macromedia installed it in the window/system32/macromed/flash directory.”

some trash links and for a Stand Alone Flash Player to uninstall Flash Player and install the Debug version of Flash Player from http://www.adobe.com/support/flashplayer/downloads.html BUT no solution for me, nothing to work.

I tried to reinstall the Adobe Flex Builder, no luck, tried to install Flex Builder as a Eclipse plugin, no luckno luck, no luck …… So if you are “HERE” when you thing nothing can help maybe the solution I will present next will help you.

I have found this trying to open a “.swf” file and see that no default program was set to open files with .swf extension, the next thing I have done was download the Download the Adobe Flash Player 10 Update for Windows and Macintosh extract the files and copy the “Player\Debug\FlashPlayer.exe” for example in “C:\”. After that I have select a .swf file and open it with “C:\FlashPlayer.exe” making this the default program to open “.swf” files.

After this simple action, BINGO no BUT no error in Flex Builde “all good to go”. I hope this can help you spare some time.