New games – maybe they’re learning

30 01 2008

Hmmm… I’m not much of a gamer these days, but what with my girlfriend still overseas, there’s time a wasting.

And if there’s anything worth wasting time in, it may  as well be a Star Wars game. This new one looks like it may just be the shit, or it could be hype. We’ll have to see. Either way – we’ll have to give it the Coach Jason test.

Star Wars : the Force Unleashed.

I particularly love the storm trooper who grabs a crate in a futile attempt to thwart the Force.





Full-text search in SQL Server Express 2005

29 01 2008

Hey, I’m not gonna re-invent the wheel. There are plenty of other sites that detail this. However, I want to note a few things:

  1. SQL Server 2005 Express is limited to 4GB per database. Keep that in mind.
  2. If you want full-text searching on it, you’ll need to download the pack with Advanced Services. (This installs nicely over an existing SQL Server Express 2005).
  3. You get to use the sweet FREETEXT and CONTAINS t-sql commands to do comparison and thesaurus-enabled searches.




Flex 3 : FluorineFx : .NET

25 01 2008

Right, I might be sold on this setup I’ve got here.

So, I’m running Flex 3 Beta 3, the new open source remoting tool from the Silent Group called FluorineFx and .NET 2.0 (under Visual Studio 2008). Now, I’d been reading through online docs, and was struggling with persistent remote objects. Basically, I had assumed that after one call to some method in a remote object, the subsequent call would be to the same object, thereby any changes made in the first call would be noticed in the second.

HOWEVER, it turns out (thanku Zoli from the Fluorine mailing list) that by default, services have a “request” scope. If you want to change this, you must modify the remoting config file in the Fluorine .NET gateway.

The code below works as intended when you change the above remote file to include “<scope>session</scope>” under the destination tag of id “fluorine”… interesting…

Note: the code below is a modification of an example by Mark Piller from the Adobe docs on Flex and .NET (pg. 6).

C# Code

City.cs

using System;

 

namespace FlexInterop

{

    public class City

    {

        // The class uses public fields for brevity.

        // It could work with the public properties too

        public String name;

        public String country;

        public long population;

 

        // Public constructor is required so instances of

        // City can be created when the arrive from Flex

        public City()

        {

        }

 

        public City(String name, String country, long population)

        {

            this.name = name;

            this.country = country;

            this.population = population;

        }

    }

}

 

 

CityService.cs

 

using System;

using System.Collections.Generic;

using FluorineFx;

 

namespace FlexInterop

{

  

    [RemotingService(“Fluorine city service.”)]

    public class CityService

    {

        public List<City> cities;

 

        public CityService()

        {

            cities = new List<City>();

            cities.Add(new City(“Dallas”, “USA”, 1248816));

            cities.Add(new City(“Chicago”, “USA”, 2873790));

            cities.Add(new City(“Tokyo”, “Japan”, 12570000));

        }

 

 

        public void addCity(City newCity)

        {

            foreach (City city in cities)

                if (city.name.Equals(newCity.name))

                    throw new Exception(“City with name “ + newCity.name + ” already exists”);

 

            cities.Add(newCity);

           

        }

 

        public List<City> getCities()

        {

            return cities;

        }

    }

}

 

 

ActionScript 3.0 Code

City.as

package com.interop

{

 [RemoteClass( alias=“FlexInterop.City”)]

 public class City

 {

  public var name:String;

  public var country:String;

  public var population:Number;

 }

}

 

 

Application.mxml

 

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:Application creationComplete=”init()” xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute>

      <mx:Script>

            <![CDATA[

                 

                  import com.interop.City;

                  import mx.rpc.events.FaultEvent;

                  import mx.rpc.events.ResultEvent;

                  import mx.controls.Alert;

                  import mx.rpc.remoting.RemoteObject;

                       

                       

                 

                  private var cityService:RemoteObject;

                 

                  public function init():void

                  {

                        cityService = new RemoteObject( “fluorine” );

                        cityService.source = “FlexInterop.CityService”;

                        cityService.addEventListener( FaultEvent.FAULT, gotFault );

                        cityService.addCity.addEventListener( ResultEvent.RESULT, cityAdded );

                        cityService.getCities.addEventListener( ResultEvent.RESULT, gotCities );

                       

                       

                        addCity();

                       

                       

                  }

                 

                  private function gotFault( evt:FaultEvent ):void

                  {

                   Alert.show( “Server reported an error – “ + evt.fault.faultString + evt.fault.faultDetail );

                  }

                 

                  private function addCity():void

                  {

                   var city:City = new City();

                   city.name = “London”;

                   city.country = “UK”;

                   city.population = 10000000;

                   cityService.addCity( city );

                  }

                 

                  private function cityAdded( evt:ResultEvent ):void

                  {

                   trace( “city added, refreshing cities list” );

                   getCities();

                  }

                 

                  private function getCities():void

                  {

                   trace( “getting all cities” );

                   cityService.getCities();

                  }

                 

                  private function gotCities( evt:ResultEvent ):void

                  {

                   trace( “received all cities” );

                   // display in a data grid

                   cities.dataProvider = evt.result;

                   }

            ]]>

      </mx:Script>

     

      <mx:DataGrid id=”cities/>

</mx:Application>





Trawling through the Flex Remoting world

24 01 2008

Well, I’ve been a-reading, powering through the offerings available on the communication between .NET and Flex.

If you don’t know why, the reason is that Flex is almost completely a client-side application, and requires a server-side application to handle everything from databasing to file uploading.

Basically, everyone seems to agree on the remoting option rather than HTTP services or WebServices and fair enough. However, a lot of the documentation seems to focus around WebORB which is a pretty fantastic tool from The Midnight Coders. It is a remoting gateway that sits on IIS (requiring version 6, and thereby Windows Server 2003, I later learned) and interfaces with classes you make in .NET. There are open-source options, the main one I have been testing is FluorineFx which seems to be the newer release of Fluorine. However, it doesn’t have all the bells and whistles of WebORB.  But – I can develop on my own machine (running XP), which is a plus as you can imagine.

Essentially, you setup a virtual directory on IIS, running .NET 2.0 and then tell Flex to run from within that .NET application. On the .NET side, you ensure your classes use the right remoting compiler directives, and on the Flex side, ensure your actionscript objects reflect their .NET counterparts. Then in Flex, use the RemoteObject control along with a source property (which is the namespace and classname of your class) and call your methods via the RemoteObject.

Phew. It’s a bit messy comparing the different implementations of Flex remoting though, and that’s what I’m currently struggling with, not to mention, using the still-under-testing Flex 3 Beta 3.

I’ll post more, with examples, when I understand more.





Flex and popups

21 01 2008

Oh the joy.

I’ve been implementing the PopUpManager to bring me customised popups. The cool thing is, it can very easily load up a separate MXML application within the popup, thereby compartmentalising the code beautifully.

For example: here’s my popup file, called Popup.as

<?xml version=”1.0″ encoding=”utf-8″?>

<mx:TitleWindow xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute>

<mx:Script>

<![CDATA[

public function functionAvail():void

{


}

]]>

</mx:Script>

<mx:Canvas y=”21” width=”554” height=”459horizontalCenter=”0>

</mx:Canvas>

</mx:TitleWindow>

And here’s the implementation: main.mxml

<mx:Application xmlns:mx=”http://www.adobe.com/2006/mxml” layout=”absolute>

<mx:Script>

<![CDATA[

//todo: import your Popup class here if it is inside a separate package

private var _window:Popup = null;

private function goItemClick(event:ListEvent):void

{

_window = Popup(PopUpManager.createPopUp(this, Popup));

_window.showCloseButton = true;

_window.addEventListener(CloseEvent.CLOSE, closeHandler);

//functionAvail() is exposed via the new _window object (_window.functionAvail())

 

_window.title = “Viewer”;

//_centre the popup

_window.x = this.parent.width / 2 – _window.width;

_window.y = this.parent.height / 2 – _window.height / 2;

}

private function closeHandler(event:CloseEvent):void {

PopUpManager.removePopUp(_window);

}

]]>

</mx:Script>