Saturday, March 15, 2008

Accessing Java Objects from Flex

From Flex it is lot more easier to access methods of Java Objects with out using any services, you can achieve this by using the "mx:RemoteObject" tag which will interact with the Java objects using AMF (Action Message Format).
mx.servicetags.Service
Details of the tag properties are available at adobe Flex language reference.
For detailed reference and example visit ASDoc link

Thursday, March 13, 2008

Brush strokes using BitmapData

Couple of weeks back I was going through the "BitmapData" class that is in the flash display package. My idea was to implement different types of brush (brush stroke) like in the photoshope into a small drawing application.Finally the whole thing became very simple.
The idea is when the user drag the mouse over the canvas we have to draw a pattern, a normal stroke will be a circle or a rectangle but here we need some custom strokes.
First we will identify a pattern which would be a combination of single pixel squares arranged to get the specific pattern.To get this pattern at run time we write a loop which uses the 'fillRect' functionality to create the pattern.
Each brush strokes would be a class on its draw function implements the fillRect according to the pattern.
dummy code will look like this
public function mouseMove(event:Event):void {
if(_drawMe){
brushStroke(_color); }
}

private function brushStroke(_color):void {
var fiber_lng:Number =30;
for(var i:int=0;i<=fiber_lng;i++){
bitmap.fillRect(new Rectangle(mouseX+Math.round(Math.random()*10), mouseY+Math.round(Math.random()*10),_pixelWidth, _pixelHight), _color);
}
}
Since we are only changing the color values of a canvas, this approach has proved very smooth and fast, and the main thing that has to taken care of is not overdoing the loops to create complex strokes.
Hope this will help in some of your application

Thursday, March 06, 2008

Developing Custom Events for FLEX

Ever wondered while coding for events, it would have been great if I had a custom event whose result event target contain what I want , then this is what you should do.

I would make a class called "CustomEvent" extending the "Events" class which will take care of all the custom event details. I also have another class which trigger the events as soon as it get the data from a webservice .

the DataEventHandler class looks something like this

package mypackage{

import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
import mx.rpc.events.FaultEvent;
import mx.rpc.soap.WebService;
import mx.rpc.soap.LoadEvent;
import mx.controls.Alert;
import flash.events.EventDispatcher;
import flash.events.Event;
import flash.display.Sprite
import components.CustomEvent;

public class DataEventHandler extends Sprite{
private var service_handler:WebService;
private var methodList:ArrayCollection;
private var isLoaded:Boolean = false;

public function startService(path:String):void{
service_handler = new WebService();
service_handler.wsdl= path;
service_handler.loadWSDL();

service_handler.addEventListener(FaultEvent.FAULT,faultHandler);
service_handler.addEventListener(LoadEvent.LOAD,loadHandler);
service_handler.GetOverviewXML.addEventListener(ResultEvent.RESULT,onOverviewResult);
service_handler.GetOverviewXML.addEventListener(FaultEvent.FAULT,faultHandler);
}
private function loadHandler(event:LoadEvent):void {
isLoaded = true;

dispatchEvent(new Event("onLoadService"));
}


private function faultHandler(event:FaultEvent):void {
Alert.show("error :"+event.fault);
}
private function onOverviewResult(r:ResultEvent):void{

dispatchEvent(new CustomEvent("OverviewEvent",r.result));

}
}
The CustomEvent Class looks like this.

package mypackage{


import mx.controls.Alert;
import flash.events.EventDispatcher;
import flash.events.Event;


public class CustomEvent extends Event{


public var itemDescription:*;

public static const OVERVIEW:String ="OverviewEvent"


public function CustomEvent(type:String,description:* ){
super(type,true, true); //bubble by default

itemDescription=description;
}

override public function clone():Event{
return new CustomEvent(type,itemDescription); // bubbling support inside
}



}

}

From the development side I would write

data_handler = new
DataEventHandler();
data_handler.startService("servicepath?wsdl");
data_handler.addEventListener(CustomEvent.OVERVIEW,onOverviewLoad);

private function onOverviewLoad(e:CustomEvent):void{

for(var ns:String in e.itemDescription){
Alert.show(ns+ "::"+e.itemDescription[ns]);
}

}
Note how we included the "CustomEvent" target object. use a for loop to get all the data stored by the result object.Hope rest of the code is self explanatory. This classes has been very useful for me.

Monday, March 03, 2008

AIR FLV subtitling application.

I was tracking the AIR development very closly through Adobe Labs(A greate place to learn RIA) AIR 3.0 Beta along with Flex Builder was a nice toy to play with, then came a requirement to add subtitles to FLV vidoes. The subtitle will be an XML file and tracked by the custom FLV player (which I developed in mid 2007 ) .
Now the trouble was preparing the subtitling file with the accurate time details of each videos, and found that's gona eat up a lot of time, so I thought why not build an AIR application and came up with the "CaptionAir".
The first thing I decided when thinking about the application was that the user are going to play with video files and hence all the button should have key board shortcuts.Other features includes users can load a file by browsing the local files or from a server path.The "start Time" and "End Time" will track the time in between the subtitle has to come.Once the subtitle text is added it comes to a list box below.
Clicking on the list box items will automaticaly takes the application to "Edit" mode and track the video to the appropriate position.Using the time scrubber at the bottom the user can sail to any position of the video and preview how the subtitles will work in run time.Clicking on the save button will export the entire subtitle information into an XML file.
Adding the certification and converting it to an installer and all are fairly simple.

Flex .Net educational portal

At last our Flex based educational portal is now ready and it is called "GoggleBox". Me and my web tech savvy project mate Sumit was asked to work on an educational portal entirely based on Flex and .Net. The challenge was too good to deny . We first worked on the over all requirements and features that could be implemented.Sumit in no time realised that we need a custom CMS engine to develop and implement this portal, while I was designing the Flex application that could be plugged and played into the system.

In between the development the challenge was to make custom events to communicate with our web service which was solved once I could develop a couple of APIs to handle the issue.Over all it was a challenging and wonderful experience.

The product was an instant hit as soon as it was launched for the BET 2008 shows at London.

visit GoggleBox