Total Pageviews

Sunday, April 28, 2013

Convert Flash ActionScript to HTML JavaScript

After Adobe donated Flex to Apache, there have been a lot of work being done by Apache Flex team. One of the substantial feature has been to convert Flex\MXML based project to HTML\Javascript. With this, flash player's dependency can be completely eliminated and flex based sites can now run on any browser without flash player addon in it.

For more:
https://cwiki.apache.org/confluence/display/FLEX/ASJS+-+From+Flash+Player+to+web+native

3 Cheers to the team!

Friday, March 29, 2013

Writing large files on mobile\android\ios from web using Flex AIR

Generally, we tend to load a file, read it and then write it on the disk, which works absolutely fine on web\desktop. But in case of mobiles\tablets, memory is a huge constraint. Smaller files may still work as intended, but in case of larger files(> 300MB), FileStream.readBytes or FileStream.writeBytes would fail as app would try to load the data in memory which would be very less comparatively and app would crash in that case. Hence, we could instead read and write data in chunks which would not affect the memory as much.

getRemoteFile("http://www.someserver.com/mobilefiles/someLargeDBFile.sqlite");

private var urlStream:URLStream;  
public function getRemoteFile(path:String):void 

            urlStream = new URLStream();
            var urlReq:URLRequest = new URLRequest(path); 
            urlStream.addEventListener(Event.COMPLETE, loaded);
            urlStream.addEventListener(ProgressEvent.PROGRESS, onProgress);
            urlStream.load (urlReq); 
 }

private function onProgress(event:ProgressEvent):void
{
           writeDataToDisk();
}

private function writeDataToDisk():void
        {
            fileLocal = File.applicationStorageDirectory.resolvePath(folderName+"\\"+fileName);
            var bytes:ByteArray = new ByteArray();
            if ( urlStream.bytesAvailable == 0 ) return;
            if ( urlStream.connected )
            {
                urlStream.readBytes(bytes, bytes.length);
                fs = new FileStream();
                fs.addEventListener(Event.CLOSE, onClose);
                fs.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
                fs.open( fileLocal, FileMode.APPEND );
                fs.writeBytes( bytes );
                bytesOffset = bytes.length;
                fs.close();
            } 
        }

Tuesday, February 12, 2013

Check internet connection for offline solutions in Flex Mobile Applications

Method 1: Using URLMonitor and URLRequest

private var mon:URLMonitor;
private var monurl:URLRequest = new URLRequest('http://www.blogger.com');

protected function isOnInternet():Boolean
            {
               //to check internet connection
               var isInternet:Boolean = false;
               monurl.method = URLRequestMethod.HEAD;
                mon = new URLMonitor(monurl);
                mon.start();
                mon.addEventListener(StatusEvent.STATUS, function(event:StatusEvent):void
                {
                    if(event.code == 'Service.available')
                    {
                        //internet connection available
                        isInternet = true;
                       
                    }
                });
                return isInternet;
            }



Method 2: Using NetworkInfo
private function checkInternetConnection():Boolean
            {
                var interfaces:Vector.<NetworkInterface> = NetworkInfo.networkInfo.findInterfaces();
                if(interfaces.length==0)
                {
                    return true;
                   
                }
                for(var i:uint = 0; i < interfaces.length; i++)
                {
                    if(interfaces[i].name.toLowerCase() == "wifi" && interfaces[i].active)
                    {
                        trace("WiFi connection enabled");
                        return true;
                    }
                    else if(interfaces[i].name.toLowerCase() == "mobile" && interfaces[i].active)
                    {
                        trace("Mobile data connection enabled");
                        return true;
                    }
                   
                }
               
                return false;
               
            }
         

Monday, May 16, 2011

Pattern based login system

1. Left click, hold and drag the mouse pointer on the dots to draw a pattern.
2. Click on 'Register' to register the drawn pattern.
3. Verify back by re drawing the same pattern or different pattern.




Thursday, April 7, 2011

Roman to decimal and vice versa converter in flex

You can convert roman numerals to decimals and decimals to romans. Roman to decimal uses modern roman notation and decimal to roman uses ancient roman notation.


Monday, March 21, 2011

Glossy Mobile Widget in Flex

Along with day and time, it also shows temperature in degree celsius.
I've used a timer which ticks every 5 seconds, just to depict the usage of different weather images, based on the current temperature, which gets generated randomly between 0 and 50.