Friday, January 25, 2008

Object Clone in ActionScript

Object.prototype.clone = function() {
        if (this instanceof Array) {
                var to = [];
                for (var i = 0; i<this.length; i++) {
                        to[i] = (typeof (this[i]) == "object") ? this[i].clone() : this[i];
                }
        } else if (this instanceof XML || this instanceof MovieClip) {
                // can't clone this so return null
                var to = null;
                trace("Warning! Object.clone can not be used on MovieClip or XML objects");
        } else {
                var to = {};
                for (var i in this) {
                        to[i] = (typeof (this[i]) == "object") ? this[i].clone() : this[i];
                }
        }
        return to;
};

Wednesday, January 2, 2008

Wrapping SWF's into Grafeio Applications

Example below shows how to load external SWF and wrap it into EmptyForm object to run as Grafeio Application:

package apps
{
  import core.EmptyForm;

  import flash.display.Loader;
  import flash.net.URLRequest;
  import flash.system.ApplicationDomain;
  import flash.system.LoaderContext;

  import org.aswing.AsWingManager;
  import org.aswing.Container;

  public class SoundCircles
  {
      private var ldr:Loader;
      private var frm:EmptyForm;
    
      public function SoundCircles(manager:*):void
      {
          super();
        
          frm = new EmptyForm(manager);
          frm.title = "Sounds Circles";          
          frm.resizable = true;
          frm.closable = true;
          frm.width = 400;
          frm.height = 400;
        
          var cmp:Container = new Container();
        
          ldr = new Loader();
          ldr.load(new URLRequest("datadreamer/2daudio/projecttwo.swf"), 
new LoaderContext(false, ApplicationDomain.currentDomain));
            cmp.addChild(ldr);  
        
          frm.child = cmp;
      }
    
      public function run():void
      {
          frm.show();
      }
  }
}

Monday, December 31, 2007

Tip: Convert Seconds into HH:MM:SS format

If you have some data like video metadata clip duration or anything else in seconds and you want to represent in HH:MM:SS format you could do following:

var d:Date = new Date(2008,1,1,0,0,seconds_value);
trace(d.toTimeString().substring(0, 8));

Sunday, December 30, 2007

Video Player with ASwing and ActionScript 3

Someone might need little sample on how to create a little Video player using ASWing UI Framework and ActionScript 3. Basically whole thing takes few lines of code, all that you need is to have latest AsWing downloaded from http://www.aswing.org and my library that I allocated under org.aswing.media namespace.

Current build of video player supports, play/pause/stop and "toggle full screen" operations. For you who don't need a video viewer with control bar, you can use org.aswing.media.VideoViewer component.

package
{
    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.events.Event;
    
    import org.aswing.AsWingManager;
    import org.aswing.media.VideoPlayer;
    
    public class SimplePlayer extends Sprite
    {
        public function SimplePlayer()
        {
            super();            
            addEventListener(Event.ADDED_TO_STAGE, init);            
        }
        
        private function init(e:Event=null):void
        {
            AsWingManager.initAsStandard(this, true);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            var vp:VideoPlayer = new VideoPlayer();
            vp.url = "robot512k_stream.flv";
            vp.setLocationXY(100, 10);
            vp.setSizeWH(400,300);            
            this.addChild(vp);
        }
    }
}

Wednesday, December 12, 2007

Google Chart API and AS3

These weekends I found that Google has own Chart API that anyone can access via REST web services, so generally speaking you just pass some values via URL request and as result you getting your Line Chart, Bar Chart Pie and etc...

The Google Chart API lets you dynamically generate charts on fly, you can get very detailed information on http://code.google.com/apis/chart/

So after having quick look into docs Google provided I've done a simple wrapper on top of Chart  API, so its functionality became available for me from ActionScript 3 as well.

You can download sample classes from http://sas3u.googlecode.com/svn/trunk/v.1.0/classes/com/skitsanos/charts/ 

A bit later on I will updated it with more functionality, for now it is just more like proof of concept.

And here is the sample of how to use it:

package
{
    import com.skitsanos.charts.ChartDataSet;
    import com.skitsanos.charts.LineChart;
    import flash.display.Sprite;
    
    public class Main extends Sprite
    {
        public function Main():void
        {
            super();
            
            var linechart:LineChart = new LineChart();
            linechart.chartTitle.title = "My money flow";
            
            var income:ChartDataSet = new ChartDataSet();
            income.values.push(15);
            income.values.push(30);
            income.values.push(35);
            
            linechart.dataSets.push(income)
            linechart.draw();
            
            addChild(linechart);
        }
    }
}

Friday, November 30, 2007

TinyWEB HTTP Server for testing your code

Few days ago I got into a problem, there is no embedded web server in damn Windows Vista whatever edition I have installed on my Laptop, I really needed one since couple of ActionScript applications I was making been firing Security Sandbox error, so I needed to solve it somehow. Basically half an hour later I had my own minimalist HTTP Server. Since it doesn't do anything except serving web pages and I don't need anything else, I named it TinyWEB and now giving it for free for everyone.

2007-11-30_003555

As you can see from this image it has only three settings:

  • Content Folder, - just point it to the location where you have content stored
  • Default Page, - to handle issues like when you typing http://localhost/ without specifying file name it will load default file.
  • Port - TCP/IP port, where you will address your HTTP requests, if you have already some other web server, you can use some alternate number, for example 88, otherwise just leave it default equal to 80.

After all hit the Start button and it will start serving pages.

If you want to hide the main window into tray icon, just click on little cross [x] button in upper corner, double click on tray icon will restore window back. And to close the application just click Close button.

And to download TinyWEB use this link: http://webservices.skitsanos.com/utils/tinywebsetup.exe

Thursday, November 29, 2007

Mass file loading and file dependencies solved in AS3

You definitely need to have a look at project masapi. The target of the Masapi is to provide a complete framework dedicated to the management of the massive loading into a flash/flex application. It is designed to be as easy as possible to use but also to be as flexible as possible.

There are the main features that the framework supports :

More details at http://code.google.com/p/masapi/

 
  © 2007, Evgenios Skitsanos