Archive for the 'AS 3.0' Category

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

May 20 2008

Allowing Popups to work

Published by under AS 3.0,Flash

In AS 2.0 or earlier when you use getURL to open up a new browser window, usually it wouldn’t get blocked by popups if the getURL call was made onRelease event instead of onPress. But with navigateToURL introduced in AS 3.0 its a different story altogether. 

navigateToURL works fine with Safari but doesn’t work in Firefox (I am a mac user so i personally test in these two browsers). Anyway to make sure that popups open we have to use some javascript and call it from our Flash.

Adobe recommends we use ExternalInterface since the 9.0.124 update. So here is my Flash code,

var boolean:String = ExternalInterface.call("openWindow", url);

if (boolean == "false"){
    navigateToURL(new URLRequest(url),"_blank");

}

and my Javascript would look something like this,

function openWindow(pageUrl) {
    var winName = Math.round(9999*Math.random()) + new Date().getTime();
    var winNew = window.open(pageUrl,winName,"toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=0,resizable=1,width=800,height=700,left=200,top=100");

        if(!winNew) {
            return "false";
        } else {
            return "true";
        }
    }

So with this method we first try to open a window using Javascript, Firefox is happy with that and hence it returns true and flash doesn’t make a call to navigateToUrl. Safari blocks the javascript popup and hence true is returned to Flash and using navigateToUrl you can open up a new browser window.

It seems to work with IE as well otherwise i would have got a bug reported from the QA team. :)

7 responses so far

Sep 20 2007

Using Interfaces with Actionscript 3.0

Published by under AS 3.0

This is a very basic example of how you can use interfaces in Actionscript 3.0. The complete set of file can be downloaded here.

Specified file is not in uploads folder, does not exists, or not a file.

No responses yet

« Prev