Union Platform : a multiuser environment with actionscript

While there are alternatives to actionscript for doing a multi-user application, Colin Mook and Derek Clayton had teamed up (to form User1.net) to do Union Platform. The platform itself provides alternative languages to develop application with, the most notable feature is one can create multi-user applications with actionscript only. Thats a lot of good news on itself. Well, even a sample server environment is free for 1000 users at one time! Huge! Its called “tryuion.com” and provides a testing ground to test your skills for a multiuser application.
The even bigger news is Union Platform is now on cloud in collaboration with Influxis and its at unioncloud.io. Union Cloud is free till its in Beta, so the time is now to build a multi user application with Union Cloud , the feature list looks awesome.
Happy Flashing


Geting started with Starling, running Flash in GPU.

With Flash player 11 comes Stage3D, which enables us to run Flash content in GPU. While its all good, coding for a simple task looks as if something real big.

Fortunately Starling-framework makes the life easier. Its a framework on top of Stage3D(codenamed Molehill). The best part of it is one can just use it as if using flash’s own API. It has movieclip, sprite, events and displaylist. While I was trying my first handson this framework, found some must to do things, which may save someone’s time.

Minimum requirement,

To run
1. First of all, it needs Flash Player 11.
2. It must be run inside a browser. Yeah, SWF must be embedded inside a HTML page.
3. Inside the embed code, “mode” must be set to “direct”.

<param name="wmode" value="direct">

4. Embeding the swf with SWFObjectdoes not work for me. So used the minimum default Object-embed method. To author 1. Need Flash Player 11 SDK 2. Overlap it on Flex SDK 4.5.1 , so that you got the compiler ready. 3. Compile with extra compiler argument as ” -swf-version=13 “.

The basic HTML boilerplate code to embed look as

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
        <meta name="google" value="notranslate">         
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="600" height="600" id="movie_name" align="middle">
    <param name="movie" value="Startup.swf"/>
    <param name="wmode" value="direct">
    <!--[if !IE]>-->
    <object type="application/x-shockwave-flash" data="Startup.swf" width="600" height="600">
        <param name="wmode" value="direct">



Happy Flashing.

Two impressive things from day one keynote of Adobe MAX 2010

Edge : A tool to take control of HTML 5 animation capabilities
Can not say more about this, one must watch the video on the link. Feels like early Flash days, when timeline was everything.
Molehill : A new set of lowlevel 3D APIs.
The details of this new 3D API and its capabilities are here at Adobe Labs. Definitely that would open up some more fun on gaming side and as we can see the demo car race is already impressive. Just thinking whether the game studios will be interested in porting the native codebase to SWF or in AIR. Or how much re-writing may be necessary for the translation. If at all the games are ported into SWF with/without the help of Alchemy can those still maintain the frame-rate and the massive multiplayer requirements (which again should not be diffiicult with P2P in Flashplayer). If those are going to be of some standard result, then I think all the games are playable in all the Operating systems. I mean the games will not only become windows only. One can play the same game on Linux, MAC and Windows. No Code re-write, hopefully I guess. As everything will boil down to AIR or SWF. Ohh, I am forgetting the AIR and Flash are coming to TVs, so gaming consoles also could take that advantage. The keynote already showed gaming controls like joysticks and steer wheels. Will Flash take on the gaming industry by storm this time?!! Time now is to just wait and watch.

IPhone game framework for Flash developers!

Let me face it. The syntaxes of ObjectiveC is very different from any other language out there. At first it is not at all readable. No. Not even a single sentace. It took me sometime to get used to it. I said get used to it, not even get going in it :) Now, the point is, once you are a little comfortable in knowing it, it even scares with pointers and memory management. Lets put that aside. Knowing a different language and how it works always helps. As a flash developer, I was wondering how to apply my skills in this language. And fortunately there are some very nice frameworks out there which can feel just right for it.

Sparrow. Yeah, its an opensource, free game framework for iphone. Finally a framework which is made for people, who have come across actionscript. I have recently completed a simple game ( as you know, flash developers start with it :) ) and can only say that it does what it says. Forget about all the difficulties of objectiveC stuff and think about your game. So, familiar things, like Sprite, MovieClip, addchild, addEventlistener, bubbling etc are all there. Its so simple that the documentation is just one page. And there is a quite nice community arround it. I must say, a very nicely done framework for actionscript developers. All the best to the Sparrow team for the effort.

Happy Flashing :)

Encapsulation : How ? Its a Dynamic Class.

This is in continuation to the previous post, Encapsulation:Why? , I thought it makes sense if we talk about the same principles to apply in a dynamic class.
First thing first, what is a Dynamic class?! Well, for those who are from AS1 and AS2 days, its in the blood kind of thing. We create an object then add on some properties to it in the runtime. But AS3 seems to take that freedom out. Well, not really, there are still some dynamic classes out there in AS3. Our very basic MovieClip is still a dynamic class. That means, we can still create new properties and methods in it. While the Sprite class is not.
Any new class we make in AS3 is known to be something called as a Sealed class. These classes cannot be modified to have new properties or methods in runtime. Whatever propeties and methods are declared at compile time is only available at runtime. So how to make a dynamic class, its just to declare a class with dynamic keyword as

public dynamic class MyDynamicClass
instead of
public class MyDynamicClass

Well, thats cool and fine. But why I would make one? The question may be answered by the way one designs an application, chances are you never want to make one or may be you just need some. So its all kind of depends how you want to program your application. Now if we make a dynamic class and add some properties, then how to controll its getter and setter as we have discussed earlier about controlling for a sealed class.
There is a very nice utility available at flash.utils package. Its the Proxy class. This does exactly, the same thing as we are searching for. Its a class, which is never being used by its own. Never instantiated. The only way to use it is to subclass it. Go over to the documentation to see a complete overview of the class.
Now lets jump directly to the code and see how it works. Then we will go on details about what it does. I think that way we can relate things while talking.  My proxy class begins like
public dynamic class MyProxyObject extends Proxy

Continue reading “Encapsulation : How ? Its a Dynamic Class.”

Encapsulation : why?

Now, I remember, I had this question when developing my first framework. At some point in time, when developing your own framework of some kind, you must be asking the same question. The question is “Why I will make properties of a class private?! When everyone is capable of accessing it, why properties would be private ?”
This reminds me of my first dive into the object oriented programming in Java. All most all the books, explained that, all the properties of an object should be private with its getters and setters as public. I asked myself, it does not make any sense to write some more lines of code for the same thing. If at all, user needs to access my properties, I can make them public at the first place.
The answer was not clear at that point in time. But as I went along and developed some couple of more frameworks for my projects, the encapsulation part slowly made sense to me.
Encapsulation is not data hiding. Yes, you heard it right. Its not hiding the data. Its bundling the data with some methods to regulate the process, how those data can be manipulated.
Lets take an example, Ball is an object, which has to be moved across the stage. Well, in that case, we can write a Ball class and use it to move by changing the x and y position of it. Thats straight enough. Now, if there is a requirement that the Ball must be moved in straight line from left to right, then what happens. We comeback to our main file, or the stage file, or wherever we have used our Ball object to move. change the code and we are done. Impressive! In the process actually we are modifying something else, not the Ball Object. Though the requirement for Ball has changed, because of our way of coding, we have to modify some other class so as to fix the problem. There comes the solution of encapsulation. What if all the movement code are there with the Ball class. In order to move it, let there be a method named “moveIt()”

public function moveIt():void
//Do code for moving the ball from left to right

Now, all we need to do is, hide the ball movement code inside our Ball object. The calling object will just call the method named “moveIt()” of the ball object. Incase there is a requirement change, and now the Ball should move from right to left, there would be no worries as to where and how to change the code. The only thing which will change is the implementation of the moving ball code inside the “moveIt()” method. There may be a direction property of ball object, which will check the direction of movement of the ball. That also could be implemented inside the “moveIt()” method as below.

public function moveIt():void
//if the ball is moving from leftToRight
//Do code for moving the ball from left to right
if(this.x>=MaxWidth)//ball reaches the rightmost point
this.direction=””;//no direction now, as ball is stopped moving
// stop the ball

Similarly if requirement is to move it from right to left, the code will look as below

public function moveIt():void
//if the ball is moving from right To left
//Do code for moving the ball from right to left
if(this.x<=0)//ball reaches the leftmost point
this.direction=””;//no direction now, as ball is stopped moving
// stop the ball

Now we can see that the private property “direction” can not be accessible from outside. but its only used inside the Ball object. So the data is encapsulated. We can still interact with it but not directly. The rules could be set as to how to interact through the public exposed methods.

Another example would be, suppose we have a property of an object, which is always a multiple of 2. But then we do not want our user to know that the property is always a multiple of 2. So we may expose the setter method as to take any integer, but internally we will be storing that as a multiple of 2. The code would be something like below

private var _myNum:int;
public function get myNum():int { return this._myNum; }
public function set myNum(value:int):void
this._myNum = 2*value;// we are not storing the user value directly

Now it makes a lot of sense to have all the properties as private. Only expose those with setters, which are really needed to be exposed. Another advantage is, any requirement change will just make us change at one place (if the value should be multiple of 3 instead of 2, we just change the setter).

Happy Flashing :)