Archive for the 'Flex' Category

Jun 22 2008

Cairngorm and Web Services

Published by under Flex

I had to use Cairngorm where the data was coming from web services and i had little trouble initially setting up services in my command class. But after a few tries and misses i was able to get web services to work. This is how i have implemented it.

Service class just defines a webservice as follows,

 

Pretty straightforward and the services are global so any changes in the server can be easily changed. Now the execute method of the command class which calls this service looks like this.

 

public function execute(event:CairngormEvent):void {
    var service:WebService;
    var operation:Operation;
    var token:AsyncToken;
    var requestObj:Object;
    var email:String = event.data.email;
    var password:String = event.data.password;

    service = ServiceLocator.getInstance().getWebService("signUpService");
//load the wsdl file
    service.loadWSDL();

//we assign the operation to the function that needs to be called inside the wsdl
    operation = service.getOperation("GetItemsFromStore") as Operation;
//the result format we need is e4x
    operation.resultFormat = "e4x";
//this object will pass all the required parameters for this function
    requestObj = new Object();
    requestObj.email = email;
    requestObj.password = password;
    operation.request = requestObj;
    token = operation.send() as AsyncToken;
//this is the line where the responder object is passed to the Asynctoken
    token.addResponder(event.data.responderObj);

}

Disclaimer: The above code is a copy paste and then modified so please forgive the coding style.

Now the fault or the result method of our responderObj will be called accordingly.

One response so far

Jun 20 2008

Connecting Cairngorm View with the Command Class.

Published by under AS 3.0,Flex

I have been playing with Cairngorm quite a bit and usually when i dispatch cairngorm event, i rely on flex data binding with the model class to manage the view. This is applicable in most of the cases but then sometimes its not required to bind some data in your view with the model. 

I came up with this solution to convert my view to a responder and then once data is fetched, I can update my view as required. Its really an easy solution, your view container has to implement mx.rpc.IResponder Interface and then in the cairngorm event you just pass its reference. It looks as follows,

<mx:Canvas xmlns:mx=”http://www.adobe.com/2006/mxml” width=”343” height=”389” show=”initModule()” implements=”mx.rpc.IResponder>

there are only two methods in this interface, result and fault, this is how my script block looks inside this Canvas.

import com.adobe.cairngorm.control.CairngormEventDispatcher;
import com.sampleapp.events.GetStoreItemsEvent;
import com.sampleapp.model.SampleAppModel;
import mx.controls.Alert;

private var model:SampleAppModel;

public function fault(data:Object):void{
}

private function initModule():void{
    if (!SampleAppModel.getInstance().albumDataList){
        model = SampleAppModel.getInstance();
        var event:GetStoreItemsEvent = new GetStoreItemsEvent(GetStoreItemsEvent.GET_STOREITEM);
        event.data = new Object();
        event.data.responderObj = this;
        CairngormEventDispatcher.getInstance().dispatchEvent(event);
    }

}

public function result(data:Object):void{
    var resultXML:XMLList = data.result[0].children().children();
    var finalXML:XML = new XML(resultXML[0].toString());
    model.albumDataList = finalXML.children();
}

and this is how the execute block inside my command class looks like,

public function execute(event:CairngormEvent):void {
    var service:WebService;
    var operation:Operation;
    var token:AsyncToken;
    var requestObj:Object;
    itemType = event.data.itemType;

    service = ServiceLocator.getInstance().getWebService("storeService");

    service.loadWSDL();

    operation = service.getOperation("GetItemsFromStore") as Operation;
    operation.resultFormat = "e4x";
    requestObj = new Object();
    requestObj.itemType = itemType;
    operation.request = requestObj;
    token = operation.send() as AsyncToken;
    //this is the line where the responder object is passed to the Asynctoken
    token.addResponder(event.data.responderObj);

}

so using the above method, We make sure that the result function inside the canvas will be called when the data is received. Now you can do whatever you need to inside this function.

Questions, Comments, Suggestions always welcome.

One response so far

Jun 16 2008

Flex/Flash Fullscreen problems

Published by under AS 3.0,Flash,Flex

I have been playing with Fullscreen mode of Flash in Flex and had this annoying problem.

My listener is setup,

Application.application.stage.addEventListener(Event.RESIZE,stageResized);

private function stageResized(event:Event):void{
    mx.controls.Alert.show(Application.application.stage.displayState);
}

and then I call the function which looks as follows,

private function fullScreenFunction(rect:Rectangle):void{

    if (Application.application.stage.displayState != StageDisplayState.FULL_SCREEN){

        Application.application.stage.fullScreenSourceRect = rect;
        Application.application.stage.displayState = StageDisplayState.FULL_SCREEN;
    }
}

Nothing wrong so far, the reason i am doing it this way is because i need to make different sections of Application full screen.

This is the function call i make, my application is 1024×768,

1
fullScreenFunction(new Rectangle(1,1,1022,766));

Above function call triggers the stageResized properly but,

1
fullScreenFunction(new Rectangle(0,0,1024,768));

doesn’t trigger the listener.

I have no clue why it does that and also i haven’t bothered to find out because that one pixel isn’t that important to me.

No responses yet

Jun 10 2008

Flex Videodisplay Component Problems

Published by under AS 3.0,Flex


These are the problems i faced in Flex 3.0 inbuilt videodisplay component. I had tried using it but gave up on it a couple months ago this post is written. I created my own videodisplay component for our application.

  • There is no video smoothing option, Very very weird since that was introduced in Flash player version 6.
  • You cannot get the netStream.bufferLength property, there is no getter for it. So you cannot display the buffer status. 
  • If you are encoding flv files which broadcast onLastSecond near the end, it will throw an error. 
  • Also there was a state problem, the player would go into unresponsive state while seeking or something like that which was completely messing up the video.

There was some else major as well but i can’t remember right now, i think it was the way videos were playing. Anyway i am happy with my custom component, which works perfect for our application.

 

I have seen that this post is the most popular among the very few posts i have, so if you need any help writing your own video display component i will be more than happy to share my knowledge. Sorry i can’t share the code for the component i have created.

 

edit: July 20th 08. 

 

Flex component might also give you problems while seeking the video to the end, specially if your buffer is long. lets say if you have a buffer of 20 seconds and someone seeks to the last 18th second then the status will be buffering and since the buffer would never get full. The status of the video will be buffering always and the video won’t play. 

 

In my custom component i had to add a condition to see the seek time and buffer length etc and then accordingly change the status of the video.

 

96 responses so far

« Prev