768x90 Getting Online Shouldn't be Tough- $7.49 .com Domains at Go Daddy

Create Game in Air or Flex Easily

I am the admirer of bored.com website, this site will help you with its games to reduce your stressing in office or work. But How you can create your own game in Flex or Adobe air with painless ? I have found a great library to help developer in making 2D game easily, it is called FlashPunk by Paul Sztajer. Thanks dude.

FlashPunk is a free ActionScript 3 library designed for developing 2D Flash games. It provides you with a fast, clean framework to prototype and develop your games in. This means that most of the dirty work (timestep, animation, input, and collision to name a few) is already coded for you and ready to go, giving you more time and energy to concentrate on the design and testing of your game.

This framework is designed for use with the free Flex framework, used for building Flash applications; by combining this with a code editor such as FlashDevelop or Flash Builder, you can import the FlashPunk library and develop games without the need of the official Flash IDE.

You can feel the delicious of features:
  • Framerate-independent and fixed-framerate timestep support.
  • Fast & manageable rectangle, pixel, and grid collision system.
  • Helper classes for animations, tilemaps, text, backdrops, and more.
  • Debug console for real-time debugging and information tracking.
  • Sound effect support with volume, panning, and fading/crossfading.
  • Powerful motion tweening for linear, curved, and path-based movement.
  • Z-sorted render lists for easy depth management.
  • Simple keyboard and mouse input state checking.
  • Quick & efficent particle effects and emitters.
Click here to see flashPunk sample game which is not for flex or flash but it is already used for android.

Download Youtube Video Using ActionScript or Air

Youtube is my favorite website and very entertaining, not only in video but also making money. How you can download youtube video to flv format? A week ago, i have little experiment to make Air application for downloading Youtube. The important thing you have to get is the video id http://www.youtube.com/watch?v=yGTg5116dCM, the action script is very simple, even you can make multiple download as many as you want, here is the script:

private function configureListeners(stream:URLStream):void {
    var _date:Date = new Date();
    var _fileName:String = String(_date.milliseconds)+".flv";
    stream.addEventListener(Event.COMPLETE, function(event:Event):void {
      var fileData:ByteArray = new ByteArray();
      stream.readBytes(fileData,0,stream.bytesAvailable);
      var file:File = File.documentsDirectory.resolvePath(_fileName);
      var fileStream:FileStream = new FileStream();
      fileStream.open(file, FileMode.WRITE);
      fileStream.writeBytes(fileData,0,fileData.length);
      fileStream.close();
     });
    downloadProgress.source = stream; //downloadProgress is ProgressBar id    
  }
  
  public static const GET_VIDEO_INFO :String = "http://youtube.com/get_video_info.php";
            
  public function downloadVideo(_youtubeId:String):void{
    var service :HTTPService = new HTTPService();
    service.url = GET_VIDEO_INFO + "?video_id=" + _youtubeId;
    service.resultFormat = 'object';  

    service.addEventListener(ResultEvent.RESULT, function(evt:ResultEvent):void{
      var request:URLRequest = new URLRequest(unescape(evt.result.toString()).split("|")[1]);
      var stream:URLStream = new URLStream;
      configureListeners(stream);
       try {
         stream.load(request);
       } catch (error:Error) {
         trace("Unable to load requested URL.");
       }
     });
     service.send();
    }

Yeah, that is a short codes, for advance application you can use as3youtubelib to search, subscribe and comment the video. I have used oauth google and youtube API for multiple uploads to youtube. And once again no webservice unless google data protocol. i use pinless oauth. Please read the previous article. Thank you.

Sort Collection Rss By PubDate in ActionScript

XML can be friendly and some times can be nightmare for me. A few days ago, i have task to sort rss results from multiple sites by the pubDate. If you see the source xml of rss, each websites has common format pubDate : Wed, 03 Nov 2010 22:31:34 +0000 . As my experience, converting string date to datetime in actionScript using DateField.stringToDate not always give you actual result and my client want get the results are sorted up to milliseconds. There are some suggestion to use XSLT to sort xml by pubDate, but my application is desktop Air, how to do that without connect to webservice and parsing the rss result to XSLT ?

ActionScript is very fast to recursive big of data. So I decide to sort rss results in XMLListCollection, here is my codes:

//_result are composite of total rss results from a number of websites.
    // _results += new XMLList(XML(event.result)..item);
    public function sortRss(_results:XMLList, sortedResults:XMLListCollection):void{
      var sort:Sort = new Sort();
      sortedResults = new XMLListCollection(_results);
          
      var sortField:SortField = new SortField();
      sortField.compareFunction = sortRssByDate;
      sortField.descending = true;
     sort.fields = [sortField]
           
      sortedResults.sort = sort;
      sortedResults.refresh();
    }
    
    public var months:Array = new Array('Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec');

    private function convertPubDate(_pubDate:String):Date{
      var arrDate:Array = _pubDate.split(/\s/gi);
      var _strDate:String = arrDate[0]+" "+arrDate[1]+" "+arrDate[2]+" "+arrDate[3];
      var arrTime:Array = arrDate.length > 5 ? String(arrDate[4]).split(/\:/gi) : [];        
      var _hour:Number = arrTime.length == 3 ? Number(arrTime[0]) : 0;
      var _minute:Number = arrTime.length == 3 ? Number(arrTime[1]) : 0;
      var _second:Number = arrTime.length == 3 ? Number(arrTime[2]) : 0;
      var _dateTime:Date = new Date(Number(arrDate[3]), months.indexOf(arrDate[2]),Number(arrDate[1]),_hour,_minute,_second);
      return _dateTime;
    }
      
    private function sortRssByDate(itemA:Object,itemB:Object,fields:Array = null):int{
    var dateA:Date = convertPubDate(itemA.pubDate);
      var dateB:Date = convertPubDate(itemB.pubDate);
      return ObjectUtil.dateCompare(dateA,dateB);
  }

Finally, it works without crash the application. I have tested from 10 websites with 25 items for each rss per 1 box, and i have 10 boxes. Total 100 websites rss that have to be sorted together by pubdate and grand total item is 2500 items.

BBAuth, Y!Oauth with pinless authentication in Air

I developed Air application which requires yahoo profile data. I think the application is little bit extraordinary since it doesn't need webservice, because my client won't it. I found Yahoo SDK for AS3 to build simple Yahoo Social Applications. It is quite satisfied to introduce me how to use Browser-Based Authentication (BBAuth) or Yahoo! Oauth, but how to make it not to open external browser and automatically get access token without invoking webservice and get verification pin? I got inspiration from twitter pinless . Fortunately, it works, you can see my screencast below:



When you click "Login To Yahoo" button, the authorize() method is executed, below is the codes.

private function authorize():void{
        YSession = new YahooSession(StormModel.YCONSUMER_KEY, StormModel.YSECRET_KEY, StormModel.YAPPLICATION_ID);
        YSession.clearSession();
        YSession.auth.addEventListener(YahooResultEvent.GET_REQUEST_TOKEN_SUCCESS, handleRequestTokenSuccess);
        YSession.auth.addEventListener(YahooResultEvent.GET_ACCESS_TOKEN_SUCCESS, handleAccessTokenSuccess);
        YSession.auth.pinlessAuth = true;
        
        var rect:Rectangle = new Rectangle(50,50, 780, 500);
        var browser:CustomHtmlHost = new CustomHtmlHost;
        var newHTMLOptoions:HTMLWindowCreateOptions = new HTMLWindowCreateOptions;
        newHTMLOptoions.x = 50;
        newHTMLOptoions.y = 50;
        newHTMLOptoions.scrollBarsVisible = true;   
        htmlBox = browser.createWindow(newHTMLOptoions);
        YSession.auth.htmlLoader = htmlBox;
       YSession.auth.getRequestToken("http://www.google.com");
      }
      
      private function handleRequestTokenSuccess(event:YahooResultEvent):void{
       YSession.auth.sendToAuthorization(event.data as OAuthToken);
      }
      
      private function handleAccessTokenSuccess(event:YahooResultEvent):void{
        YSession.auth.token = event.data as OAuthToken;
        htmlBox.stage.nativeWindow.close();
        YSession.setAccessToken(event.data as OAuthToken);
        gridProviders.addItem({token: YSession.auth.token.key, secret: YSession.auth.token.secret});
      }

The screencast seems little fool, because i use callback to www.google.com, but you can use any redirect url, eg: to your webservice, your domain or yahoo.com. Aside issues, to make my pinless authentication work sexier, I should hacks some line codes in YahooSession.as and AuthorizationRequest.as . (You can copy paste from these links). After i get the accessToken and accessSecret, i store them in sharedObject, and then re-validate any time you want extend the expired token. So what is CustomHtmlHost? Adobe has changed the policy for HTML where HTMLLoader is no available if you create directly new HTMLLoader, it is little hack solution from me:

package com.yahooStorm.utilities
{
    import flash.display.NativeWindowInitOptions;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.html.*;

    public class CustomHtmlHost extends HTMLHost
    {
        import flash.html.*;
        
        public function CustomHtmlHost():void{}
        
        override public function 
            createWindow(windowCreateOptions:HTMLWindowCreateOptions):HTMLLoader
        {
            var initOptions:NativeWindowInitOptions = new NativeWindowInitOptions();
            var bounds:Rectangle = new Rectangle(windowCreateOptions.x,
                                                 windowCreateOptions.y, 
                                                 1000,
                                                 650);
            var htmlControl:HTMLLoader = HTMLLoader.createRootWindow(true, initOptions,
                                        windowCreateOptions.scrollBarsVisible,bounds);

            htmlControl.addEventListener(Event.COMPLETE, onCompleteWindowHandler); 
            return htmlControl;
        }
        
        public function makeWindow(options:HTMLWindowCreateOptions):HTMLLoader{
          return createWindow(options)
        }
        
        public function onCompleteWindowHandler(event:Event):void{
        }
        
        override public function windowClose():void
        {
            htmlLoader.stage.nativeWindow.close();
        }
        
        override public function updateTitle(title:String):void
        {
          htmlLoader.stage.nativeWindow.title = "Placepoint Browser: " + title;
        }
    }
}

I am very interested to make BBauth pinless version work too in Flex and Flash As3 and then build the package scripts to swc, but i still have no time to do that, ASAP i will post the swc and documentation here.

If there's any question or suggestion please post in the comment box. Thank you.

 
powered by Blogger