Thursday, 22 November 2012

Facebook ActionScript API


The new Adobe ActionScript 3 SDK for Facebook Platform API, fully supported by Facebook and Adobe, makes it easy to build applications that combine the strengths of the Flash Platform. Developed by gskinner.com, this class library facilitates the development of Flash Platform applications that communicate with Facebook using the OpenGraph API.
The Adobe Flash Platform and Facebook Platform provide the ideal solution for building rich, social experiences on the web. Flash is available on more than 98% of Internet-connected PCs, so people can immediately access the applications, content, and video that enable social interactions. The Facebook Platform is used by millions of people everyday to connect and share with the people in their lives. Together, both platforms allow you to:
  • Share: Create rich interactions for users to share with friends.
  • Have fun: Make games social; let users compete against their friends.
  • Connect: Let users connect to your RIAs with Facebook Connect.
  • Solve problems: Build RIAs that harness the power of community.
  • Reach people: Reach millions of Facebook users through social distribution.

Getting Started

For tutorials, articles, and videos on using the new API, visit the Facebook page on the Adobe Developer Center. You can also see the docs for the most recent and stable build.

You can find the API at the following link :-

http://code.google.com/p/facebook-actionscript-api/downloads/detail?name=Facebook_library_v3.4_examples.zip&can=1&q=Deprecated

Thanks,

Bhaskar Pandey

Wednesday, 21 November 2012

Shumway : Running swf without Flash Plyer/ Using JS Runtime and Mozilla's VM


It seems that Shumway can give a new life to Flex. Because two major problems with Flex are seems to be fixed i.e. Multithreading (with worker process) and now running swf without Flash player (with Shumway).
Shumway is an experimental web-native runtime implementation of the SWF file format. It is developed as a free and open source project sponsored by Mozilla Research. The project has two main goals:
1. Advance the open web platform to securely process rich media formats that were previously only available in closed and proprietary implementations.
2. Offer a runtime processor for SWF and other rich media formats on platforms for which runtime implementations are not available. is an experimental web-native runtime implementation of the SWF file format. It is developed as a free and open source project sponsored by Mozilla Research. The project has two main goals:
1. Advance the open web platform to securely process rich media formats that were previously only available in closed and proprietary implementations.
2. Offer a runtime processor for SWF and other rich media formats on platforms for which runtime implementations are not available.
The Open Web can be further advanced by making rich media capabilities,previously only available in Flash, also available in the native web browser stack. Shumway is an exciting opportunity to do that for SWF, and we welcome support from external contributors as we advance the technology. We are reaching out to technical users who are interested in contributing to the Shumway implementation in these five areas:
1. Core. This module includes the main file format parser, the rasterizer, and event system.
2. AVM1. JavaScript interpreter for ActionScript version 1 and version 2 bytecode.
3. AVM2.  JavaScript interpreter and JIT compiler for ActionScript version 3 bytecode.
4. Browser Integration handles the glue between the web browser and the Shumway runtime.
5. Testing/Demos. Add good demo and test files/links to Shumway.

Enjoy the runnig example of swf in the following link :-

http://mozilla.github.com/shumway/examples/inspector/inspector.html?rfile=../racing/race3.swf

However I noticed that the performance of the example is vary from system to system and browser to browser.. It displays a very high performance in Mozilla Firefox browser. Also you'll found that the running swf(i.e. race3.swf) displays better performance on Shumway as compared to Flash player.(You can download the example and can run the swf on your system.)

Thanks,
Bhaskar Pandey

Multithreading with FLEX Worker Processes

The concept of concurrency is kind of the holy grail for most ActionScript developers who are working on complex projects. How many times, have you had issues with the UI locking and having to distribute computations to frames like crazy? How many times did you have to optimize your algorithms like crazy to minimize the cost of execution and reduce the risk of UI locking?

How does it work?

  • Before we start, let's cover two simple notions. In this article, we will refer to the UI worker (the one you always worked with in the past) as the primordial worker. It is still the entry point of your app, the primordial worker is never created by user code and is created automatically by the runtime, it is essentially your good old document class, extendingSprite at least.
    So to create your child worker from the primordial worker, you will just write:
    1.var worker:Worker = WorkerDomain.current.createWorker(Workers.EncoderWorker);
    As you can see, the Worker is created through the help of the WorkerDomain object, that you can see as a factory. One and only WorkerDomain object exists for the entire runtime, and cannot be constructed by user code. Workers.EncoderWorker points here to our embedded worker using the [Embed tag].
    At this point, our background logic is not executed, to trigger this, we simply use the start() API:
    1.worker.start();
    Now, the code you would have in the constructor in your background worker is started and waiting for the action. The Worker class has a state instance property to allow you to check at any time which state is your worker in. The different states are available through constants of the WorkerState class: NEWRUNNINGTERMINATED
    You could create as many workers was you want, but keep in mind that it is costly to create tons of them, each Worker is in fact a constrained virtual Flash Player instance, so it has a cost in memory (5-7mb). Ok, so now we need to communicate between workers. For this, please welcome the MessageChannel API. To communicate and send a message from a worker to another, you would create such a message channel like this:
    1.var mainToBack:MessageChannel = Worker.current.createMessageChannel(worker);
    The Worker.current call refers to the current worker (the primordial) worker, communicating with the background worker, passed here in parameter of thecreateMessageChannel API.
    Now, we have our messaging channel in place, at any time, we can just call send() on the MessageChannel object to pass data to the background worker. But wait, we need a way to retrieve this message channel on the other side, so that we can communicate. For this, you will use the setSharedProperty API, which will put a reference to your message channel so that the child worker can grab the reference and listen to the messages coming in.
    So, from the primordial worker you would write:
    1.worker.setSharedProperty("mainToBack", mainToBack);
    And in your child worker:
    1.mainToBack = Worker.current.getSharedProperty("mainToBack");
    Note that the String used here should be (to make things clean) something reflect the package of your program, I am using here something obvious to reflect the direction of the communication very clearly. So there we are! To pass data, we can now use our message channel pipeline. Also, remember that the setSharedProperty API can also be used to simply pass values to be used during the initialization of the Worker.
    In your application you may want to send data like a String, a Number, an Array or other lightweight types like this, for this you can just use myChannel.send(), the protocol used behind the scenes is AMF3. You can also send custom classes, it will behave as a ByteArray.writeObject/readObject. You would then need to register your class with registerClassAlias. For the ones familiar with Flash Remoting or Flash Media Server, you guys get the idea, your data will be copied and serialized through the rules of AMF3. So no way to pass any DisplayObject between workers for instance, as it is not supported by the AMF3 format. Also, keep in mind, that most data types passed through MessageChannel are serialized (copied) at the exception of a few I will cover later in this article.
    So let's say you want to pass an int to a worker, you would write:
    1.mainToBack.send(100);
    On the other side, you would simply write:
    1.var value:uint = mainToBack.receive();
    You would usually place the receive() call in the Event.CHANNEL_MESSAGE event handler dispatched by the MessageChannel object. Now, the receive() call has two flavors: Synchronous and asynchronous which is actually super useful. In some cases you may want to block and wait until the sending worker has sent the message, that's why there is ablockUntilReceived parameter on the receive() API. By default, it will not block.
    You can also queue multiple messages:
    1.mainToBack.send(100);
    2.mainToBack.send(true);
    3.mainToBack.send([10,20]);
    On the other side, you can consume them by just checking the messageAvailable property on MessageChannel and consume each of them by keep calling receive().
    1.while ( mainToBack.messageAvailable )
    2.mainToBack.receive();
    So now you may wonder, ok this is really cool but what if I have big amount of data to transfer, like, let's say a BitmapData, or more simply a ByteArray? Well, here comes shared memory to the rescue!

    You can find more knowledge on the following link..

    http://www.bytearray.org/?p=4423


    Thanks,

    Bhaskar Pandey