Flashing Again

November 5, 2009 by saumya

As the flashplayer is moving into 10.1 number,I think Flash player 10 itself has a lot to give me as a developer.

What I found recently is there are some amazing magic methods and tools in AS3,FlashPlayer10 and in flashCS4 IDE.
I have attached a FLA having the source code on the first frame to keep things simple :)

1. The inverse Kinematics (IK) :
This is Flash IDE and I am amazed with the Bones tool and the IK of it.The thing is one can use the IK at

authortime and if required one can make all the IK interactions runtime with just a user selection. Once all the

bones are drawn,select the “Armature” layer which “Bones” tool creates by default.Now you can see an option in the

properties pannel to make the IK “runtime” or “authortime” and VOILA!!Thats short,sweet and simple.Yay.

Next we will jump into some actionscript.

2. EXIT_FRAME

We all flash developers are born with “enterframe” events with us. Anything,anytime not working,simply write an

enterframe event-handler and throw some debugging code there. Well,for developers from Macromedia Director or

Lingo scripting world coming to Flash almost always miss their weapon,” to know when” the framehead leaves the

current frame. The good news is now we have an event named “EXIT_FRAME” and this works the same way as

“ENTER_FRAME”.So there we go,if we want to controll the frame exactly the way we want,there are two events we can

check for and do the desired stuff in-between.
The attached FLA has got the “trace” statements for the enterframe and exitframe events just to make the test.

3. addFrameScript()

Next is the un-documented method of a movieclip.I think this one we all flash developers were looking for a

long time. What it does is, add a script to a frame in the movieclip and rightly called “addFrameScript()”. The

example FLA has got the authortime IK animation controlled,by pushing in actionscript into the frame of the

movieclip. The code looks like
this.barClip.addFrameScript(10,myFunc);

4. describeType

I am quite excited to share these. For me these are real new and useful stuff,which make me think again as to how

to write my next flash application. Now the time for debugging,if I am right the first thing one do in a flash

trace statement is
trace(this);
Wow,that gives me the current object on my output panel.What else,if I want to know any property of the object I

will go ahead and do the same trace with the properties in the trace.
trace(this.myProperty);
I really got excited,when I got to know about a nifty function on “flash.utils” package.The name of the function

is “describeType”.What it does is returns an XML object of the parameter object we pass in to the function.Thats

huge. I mean it gives all the deatils of that object,I mean all the details.

Now I am putting down here, the whole code there in the FLA just in case you want the code only.

import flash.events.*;
this.addEventListener(Event.ENTER_FRAME,onEntry,false,0,true);
this.addEventListener(Event.EXIT_FRAME,onExit,false,0,true);
//import flash.utils.describeType
trace(this.barClip);
this.barClip.addFrameScript(10,myFunc);
function myFunc():void
{
this.barClip.stop();
}
//
function onEntry(e:Event):void
{
trace(‘: Entry on frame : ‘,this.currentFrame);
}
function onExit(e:Event):void
{
trace(‘: Exit from frame : ‘,this.currentFrame);
if(this.currentFrame==100)
{
this.stop();
this.removeEventListener(Event.ENTER_FRAME,onEntry,false);
this.removeEventListener(Event.EXIT_FRAME,onExit,false);
trace(describeType(e));
this.barClip.addFrameScript(10,null);
this.barClip.play();
}
}

With that I am hoping these tips may open your door to new innovations in the way we script and do stuffs in

Flash.
Happy Flashing. :)

Why so silence?!

October 28, 2009 by saumya

Its a long time. I am silent here!! Am I dead?! I hope no, but if it will be for any longer, I am sure will be dead. Why the silence? Probably its the twitter, which made me lazy. But I can not blame something/someone for my mistake. I admit, I am the culprit here. And will advice everyone who are shifting from blogging to twitting, that twitter is good but so as blogging. So keep the good habits and never leave the blogging community. Finally I am returning here and will try and put up posts regularly. Whether it is technical or not I am not sure now(though,I will try my best to keep it as technical as possible), but the thing is I want to get back to my regular habit of posting something up here.

Thank you all for visiting me and will try to keep up to the expectations :)

Flash Player 10.1 is announced

October 6, 2009 by saumya

Adobe has announced Flash player 10.1 and with it comes a whole new era of Flash applications.It might seem that this is just a point release,but do not get fooled away by the point.For me it seems like a whole new Flash world. There are so many great things coming, the details can be found here (http://labs.adobe.com/technologies/flashplayer10/)
From developer’s perspective Global error handling is a one point solutions for all the try-catch blocks. Wow, I am so excited. Then comes multitouch,accelerometer,orientation detection for mobile devices just to name a few. FP10.1 will support HTTP streaming,another great addition to flash player.This is huge again.Now with Flash player 10.1 we will get direct access to microphone. Wow,simply awesome. Flashplayer will take advantage of Hardware acceleration whenever possible,even for Vector graphics and images(http://www.adobe.com/devnet/logged_in/jchurch_flashplayer10.1.html).
Well and the most tremendous part is Full flash player is now available for mobo devices.(http://www.adobe.com/aboutadobe/pressroom/pressreleases/200910/100509AFPforMobileDevicesandPCs.html)

Last,but not the list is Flash can now make applications for iphone,yeah from Flash CS5 one can directly produce native ObjecticeC code to deploy into iPhone(Obviously one need to go to Apple AppStore for the so called approval,huh!).
http://www.youtube.com/watch?v=M3CI5GyNXoA

Overall for me as a Flash developer this seems to be a new era coming to Flash platform.I can feel the freedom and fun. Long-live Adobe and long-live the Flash/SWF team at Adobe.

References :

http://www.adobe.com/devnet/logged_in/jchurch_flashplayer10.1.html

http://tv.adobe.com/watch/max-2009-develop/building-mobile-applications-with-adobe-air

http://www.adobe.com/aboutadobe/pressroom/pressreleases/200910/100509AFPforMobileDevicesandPCs.html

http://www.youtube.com/watch?v=M3CI5GyNXoA

Happy Flashing

Introduction to SQLite on AIR

August 30, 2009 by saumya

SQLite is a relational database right inside Adobe AIR environment. While its a full fledged relational database system,the real power of  it comes from the ease of use. There is no server to configure,no server to start. Once Adobe Integrated Runtime (AIR) is installed in your system, you are ready to take  advantage of SQLite database. Actually SQLite comes with the AIR itself. So there is absolute zero configuration as it is clearly noted in the SQLite official site.

Now,all that one need to know is the Flash (Actionscript 3.0) APIs to start talking with the Database.

To begin with any database applications,one need to have a database in a database server,start the server,connect to it and then start putting in data or getting the data. Now in this case of SQLite, we already have the initial set up ready for us. I mean as a SQLite developer on Flash platform one need not worry about the server setup and starting the Database server. All one need to concentrate is, connecting to the Database and puting some data in or getting some data out from the database. For once AIR is installed SQLite is up and running,how cool :) ! Now the best part is,all the standard SQL query runs in the SQLite Database too. To get started, one need to create a database or connect to it,if already created. Now SQLite API gives us one syntax to do the both,I mean if the database is already present it just connects to it else it creates the Database for us and then connects to it. The syntax is as below

var conn = new SQLConnection();//Connect to the DB server
//adds event listeners to listen for the events
var conn.addEventListener(SQLEvent.OPEN, onOpenConnection);
var conn.addEventListener(SQLErrorEvent.ERROR, onConnectionError);
//connects or creates and connects to the database
var dbFile:File = File.applicationDirectory.resolvePath(“myDb.db”);
conn.openAsync(dbFile);//actually connecting to the Database

Thats all to create and connect to the database. By convention the database files are named with extention “db”,In this example we are creating a Database file named “myDb.db”. The Database is actually stored as a file,as we created now. To make any query to the Database the syntax will go as below

var sqlStatement:SQLStatement = new SQLStatement();
sqlStatement.sqlConnection = conn;//”conn” is the connectino we just made with the above code
var query:String = “SELECT * FROM friends”;//This is actual SQL query we are going to run in the Database
sqlStatement.text = query;
//adds event listeners to see if our query ran properly
sqlStatement.addEventListener(SQLEvent.RESULT, onQueryResult);
sqlStatement.addEventListener(SQLErrorEvent.ERROR, onQueryError);
sqlStatement.execute();
//finally calls to run the query in the Database

Thats all to it. :)

Now to make things easier for my project,I have created a helper class for regular tasks as querying the Database and getting the result. Please find the file at google code repository here. Hope that helps you on your day to day task of SQLite development under AIR and Flash platform.

happy flashing

10 development environments for iPhone

August 3, 2009 by saumya

On my previous few days of diving  into iPhone development, found some promising environments for the iphone development.

1.  unity ( http://unity3d.com/unity/features/iphone-publishing )
This is an IDE,for 3d Graphical Object authoring which has compelling capabilities regarding the content creation.
Pros : With in-built events handlers(behaviours) and native iphone support looks very promising as far as the content creation and delivery are concerned. Full light,shadow and materials in a 3d environment is just a full fledged game development environment. The IDE can be used in both Windows and MAC.
Cons : A very high price tag.

2.  torque2d ( http://www.garagegames.com/products/torque-2d/iphone )
This is an IDE for 2D Graphical Object authoring. WYSIWYG 2D editor at iPhone screen resolution. Has got a 3d IDE (http://www.garagegames.com/products/tge/iphone) for iphone.
Pros  : Makes a complete game development environment as the Objects are visual and a custom scripting environment for the obejcts, same kind as Unity but 2D environment. Option to divide the 2D and 3D games as per requirement.
This IDE can be used in both Windows and Mac.
Cons : Still a high price tag and not a clear Licensing model.

3.  ston3d ( http://www.stonetrip.com/shiva/publish-3d-game-on-iphone.html )
This is an IDE(http://www.stonetrip.com/) for 3D authoring as Unity and Torque.
Pros  : Makes a complete game development environment as the Objects are visual and a custom scripting environment for the obejcts, same kind as Unity and Torque.
Runs on both Windows and Mac.
Cons : Still a high price tag (http://www.stonetrip.com/platform/view-all-products.html)
the iphone exporter only works in Mac.

The IDEs are too good for a complete game development environment,where the developers and designers work in the same IDE.Graphics can be done and kept as library items and then developers can take those to add the desired behaviour. This will be much like developing the Flash IDE with actionscript. But then all of the people invloved in the development must have teh clear knowledge of the environment and the developers must learn the new languages specific to the IDEs.

4. nui ( http://libnui.net/pages/about.php )
A C++ framework designed to build multiplatform applications on top 3D rendered dynamic layouts.

Pros : platforms supported are iPhone, MacOSX, Win32, Linux
Cons : High price tag, only coding and no graphics IDE will increase the complexity of development.

5. HAXE (http://ncannasse.fr/blog/haxe_for_iphone)
A language to create projects in multiple platforms.
Pros : An actionscript like language,with which flash developers can get upto speed very fast. Publish the application in different environment(Haxe publishes to SWF,Javascript,PHP and C++ now)
Complete Opensource development.
Cons : The present support for iPhone is a JailBreak one.

6. PyObjC (http://pyobjc.sourceforge.net/)
A python language derivative to create ObjecticveC applications
Pros : Can use Python knowledge to develop. Opensource development.
Cons : Does not make any sense for a flash developer,anyway has to study a new language. At (http://www.saurik.com/id/5) it says one still need to know ObjectiveC.

7. alcheMo-for-iPhone (http://innaworks.com/alcheMo-for-iPhone.html)
pros : Use java to develop iphone applications. Seems its the only one which does not require Jailbreak or any other tweeks to develop for iPhone in Java.
cons :  Neither Download norLicensing are clear.

8. QuickConnect (http://quickconnect.sourceforge.net/browser/index.html)
A javascript framework to develop iphone apps.
pros : will be easy and fast develoopement as it is in javascript. Multiple platform deployment.Since it is open source and liberally licenced you can use it to develop for your open source, free projects or closed source, for-cost projects.
cons : still a Release candidate.(http://sourceforge.net/projects/quickconnect/)

9. XMLVM (http://www.xmlvm.org/iphone/)
An XML driven iphone application development.
pros : Simple and fast as its all XML. Opensource.
cons : Needs Jail-break (http://plum.sfsu.edu/xml11-external/java4iphone-google.pdf ,page 28)

10. The Cocotron (http://www.cocotron.org/)
This is an open source project which aims to implement a cross-platform Objective-C API similar to that described by Apple Inc.’s Cocoa documentation.
pros : Cross platform developement,so can be developed on windows.
cons : Need to learn ObjectiveC. Still seems premature.

While all of the programming environments either seem under heavy development or missing tutorials,its a good idea to keep an eye on them as all of them seem promising. Same with the graphical IDEs. Would like to see HAXE coming up as my personal favorite from a flash developers point of view. :)

My first experience with iPhone development

August 2, 2009 by saumya

Recently I started diving into iPhone development as a matter of a project requirement. I had never used MAC before and for me the Operating system is new. So I took time to understand things there first.Why? For,iPhone development you must get a MAC running on intel core!!Yeah,you must get into the Leopard Operating sytem with an intel core. Next is an IDE and fortunately you are provided with an IDE in MAC named XCode and for visual integration of components the IDE is called InterfaceBuilder. Now to develop for iPhone is to develop in ObjectiveC and its the same language used (except for some package differences) to develop for any other product of MAC and I felt good about that. The framework used is called COCOA and its on top of Objective-C language.
Objective-C is a written on C and its not C++. For a flash AS3 developer (any OOP language developer) it will look the same if you are keen to adopt the new coding standards in the language. The basics are intact as you have classes and events. Everything happens arround them but then there are strict guidelines as to how these classes and event handlers should be written and glued together.Well, the main differrence in Flash and iPhone development will be the player. While SWF still plays its content as a software renderer, Objective-C programs natively plays on the hardware and the UI elements are bitmaps which is in contrast to basic of Flash’s vector renderer.Obviously one does not have the timeline :) but there are multi-touch and accelerometer to give one hell lot of a option to play arround.
Well,after one completes a product for iphone one need to send it to Apple for approval of the product to be installed in the iphone. Once approved anyone can get it through AppStore. To submit to AppStore one need an account though,which is not free even for free applications.

Rajgad,trekking experience

June 29, 2009 by saumya

Well,this is not the first time I have trekked but this  is obviously this seemed to be the first time to trek after such a long period of time.  The journey was quite safe and sound. We started off from Thane in the midnight,reached Pune in the morning. Then with multiple vehicles’ shifting  from one to another and walking quite a distance finally reached the foot of the mountain containing the Rajgad Fort. While waiting for another 2 of our group members we lost a sever amount of morning time. Keeping our guts alive we have started to climb around 10.30AM with the sun high on the sky. While all of us were expecting rain and packed up our bags with all the rain protecting materials,the weather had a different story to tell. Taking a lot of small to mid size breaks through out the climbing, finally reached  the top around 1.30 PM.

While the climbing up was a bit more stressful than usual because of sun,but no rain came in favor of us as we never found any slippery path to lead us to trouble. Once reached top the weather was cold and cloudy. It almost started raining within an  hour,by that time we had placed ourselves inside the temple. Cooked the lunch,took some rest and started to go around  the hill,to visit the forts.

The night stay in the temple was shared with around 70 people from different teams. We cooked  the dinner and had to manage with less Dal than Rice. Then the morning was awesome with noodles in the breakfast and then moved around for visiting some different forts. And then the climbing down started.

Overall, it was a cool journey. Everyone of us were perfectly fit throughout the trek. There were spots, which we had to climb almost 70 degrees slope and on the side of the hill. These were spots which had only rocks in it and you have to make your mind before climbing up/down.

Made some cool new friends. Knew some friends in depth. Got an experience for life time. And finally get my old  dream of visiting  places rolling.

Thank you guys for making me a  part of the trekking team.Looking forward to keep up with you guys.

:)

PDF2SWF : Auto conversion from PDF to SWF

June 25, 2009 by saumya

I never thought I will be converting some PDF files into SWF anytime. But the time has come and I was doing the same for past some days. Well,while deciding for the tools and technology I always thought FlashPaper is a good option. Surprisingly for me FlashPaper is dead now ! In the beginning days I always asked myself why FlashPaper was created from Macromedia ?! But then situations come up,where one has to fall back to flash technology. Well, with the death of FlashPaper, I lost hope, then found Scribd. Awesome, they do the same thing online and have a rich set of API exposed for developers to do the same. Unfortunately, for security reasons my option only include softwares which can be used in-house.

Well, then I came across SWFTOOLS. An opensource library of tools for SWF. One of the tools is PDF2SWF. As the name suggests, it converts a complete PDF to SWF. It not only just converts PDF to SWF but also maintains all the links in the PDF in the generated SWF. Thats a pretty nice job. It has a GUI too for those who want to use it. Personally I found the command line of this tool to be awesome. There are a large number of options available while converting from PDF to SWF. By default once the SWF is created it starts running as a presentation in a default timer. There is an option to put “stop()”  action in each frame(as each page becomes one frame),nice and sweat. The default conversion gives a nice default viewer to navigate to different pages,zoom in/out and scrollbars. One can customise the default viewer to make ones one viewer too.

The only thing which hurt me is the SWF produced in a AVM1 Movie,though SWFTOOLS says that the latest version produces AVM2 movies,but it is not. To make an AVM2 movie I just passed in the flashplayer version 10.0 in one of the command line options.That gave me an AVM2 movie. For my custom player, I just went ahead and loaded the movie with an “Loader” and since its AVM2,I typecast it to a “MovieClip” and then started controlling it through AS3.

I am expecting more from the tool and the first expectations is, it should produce an AVM2 movie. The method to add a viewer should be more easier.

Over all, the tools are just freaking cool. All the best to the SWFTOOLS. Hoping to see this project mature.

Lastly below are the options one will get while firing up PDF2SWF from command line. I have just copied the help from PDF2SWF from my command line to put it here.

Usage: pdf2swf [-options] file.pdf -o file.swf

-h , –help                    Print short help message and exit
-V , –version                 Print version info and exit
-o , –output file.swf         Direct output to file.swf. If file.swf contains ‘%’ (file%.swf), then each page goes to a seperate file.
-p , –pages range             Convert only pages in range with range e.g. 1-20 or 1,4,6,9-11 or
-P , –password password       Use password for deciphering the pdf.
-v , –verbose                 Be verbose. Use more than one -v for greater effect.
-z , –zlib                    Use Flash 6 (MX) zlib compression.
-i , –ignore                  Allows pdf2swf to change the draw order of the pdf. This may make the generated
-j , –jpegquality quality     Set quality of embedded jpeg pictures to quality. 0 is worst (small), 100 is best (big). (default:85)
-s , –set param=value         Set a SWF encoder specific parameter.  See pdf2swf -s help for more information.
-w , –samewindow              When converting pdf hyperlinks, don’t make the links open a new window.
-t , –stop                    Insert a stop() command in each page.
-T , –flashversion num        Set Flash Version in the SWF header to num.
-F , –fontdir directory       Add directory to the font search path.
-b , –defaultviewer           Link a standard viewer to the swf file.
-l , –defaultloader           Link a standard preloader to the swf file which will be displayed while the main swf is loading.
-B , –viewer filename         Link viewer filename to the swf file.
-L , –preloader filename      Link preloader filename to the swf file.
-q , –quiet                   Suppress normal messages.  Use -qq to suppress warnings, also.
-S , –shapes                  Don’t use SWF Fonts, but store everything as shape.
-f , –fonts                   Store full fonts in SWF. (Don’t reduce to used characters).
-G , –flatten                 Remove as many clip layers from file as possible.
-I , –info                    Don’t do actual conversion, just display a list of all pages in the PDF.
-Q , –maxtime n               Abort conversion after n seconds. Only available on Unix.

Happy Flashing :)

Getting the Classes from external SWFs

May 24, 2009 by saumya

When it comes to divide a flash application into separate swfs, its a whole new ball-game in AS3 than in AS2. In this particular case I think AS2 was rocking and simple. But then its as simple in AS3 as in AS2,one just need to change the thought process. First of all one must understand that whatever is happening in AS3 is an Object-Event process. Then everything seems clearer. So lets start the code part.

I have two SWF files, one is having audio library and one is my application FLA.In my audio Library FLA, I have two audio files in the library,with Class name as “saumya.audio.One” and saumya.audio.Two”. These two files are set to “Export for Actionscript” and “Export in Frame 1″. So this library FLA does not contain anything else except two “mp3″ in library with the above settings. Now lets publish the FLA to produce a SWF file. Let the file named “audioPackaging.swf”. We have the audio library in place. Now all that remains is access these classes from my main container or application SWF. There is another FLA, which is supposed to be the base container or the main application FLA. This file is supposed to load the audio library into it and play them. The process of loading is same as loading any other SWF,using “Loader” class.

Once”audioPackaging.swf” is loaded into the application SWF, we will get the “LoaderInfo” object from the complete event object. This “LoaderInfo” object is the key to get all the classes in the loaded SWF. We will go into detailed descrition once we see the code. Below is the code to load the SWF and then access the “LoaderInfo” object.

var l:Loader=new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE,onSongs);
l.load(new URLRequest(“audioPackaging.swf”));
function onSongs(e:Event):void{
trace(e.target);
var lf:LoaderInfo=LoaderInfo(e.target);
}

All the classes in an externally loaded SWF is loacated inside an object of “ApplicationDomain” class. This class is in the “flash.system.ApplicationDomain” package. Do not worry if the words seem alien to you. These are actually our new friends in AS3 :) . Now the good news is to find our friends we do not have to search anywhere! There is a property in “LoaderInfo” object which contains our friend “ApplicationDomain” and the property is called “applicationDomain”. Phew,there we go. The revised code now look like

import flash.system.ApplicationDomain;

var l:Loader=new Loader();
l.contentLoaderInfo.addEventListener(Event.COMPLETE,onSongs);
l.load(new URLRequest(“audioPackaging.swf”));
function onSongs(e:Event):void{
trace(e.target);
var lf:LoaderInfo=LoaderInfo(e.target);
var Two:Class=    (lf.applicationDomain.getDefinition(’saumya.audio.Two’))as Class;
var t:Sound=new Two();
t.play();
}

Now you can see we have a method in “ApplicationDomain” class which actually returns the Class definition object. If you still remember we have already assigned the class name to the second audio file in the properties pannel as “saumya.audio.Two”. Once we get the reference to “ApplicationDomain” object, its a matter of calling the method “getDefinition(‘classDefinition’)” of this object and casting it as a Class. Thats all.We will have a proper Class definition now onwards. since we know that “saumya.audio.Two” is a “Sound” class, we can go ahead and play it like any other “Sound” class.

I had put this example for “Sound” as audio was and still is a painful part in flash application development. But the concept can be applied to any class definitions you may want to load dynamically or want to share as a separate SWF.

Happy Flashing :)

Its Application design,where innovation meets talent.

May 23, 2009 by saumya

I was thinking of putting this blog post a long time ago.Somehow I was not able to find the right subject for it.
When comes to application design its not about how good you can code a class.Yeah, I said how GOOD(its not the fix,its a good practice of code,not even mediocre) you code a class.First and foremost is a good coding practice.If you think you are a problem solver then try out good practice in code,the coding standards.This is the starting point of an application designer. Architecting a software is not just quick fixes. Its the foundation of a good building. I had come across many development firms and big corporates,where they only talk about get the things done.How?They simply do not know. I have seen talented developers are driving crazy by stupid managements.Huh,is it the future?!! As a result no innovation,no development growth as a team.
Read the rest of this entry »