Search Box


Tuesday, September 11, 2007

AS3 Migration......


Hi folks,
it's been a long time once again. Latest news at my end is that i have started working on AS3 and i need to say at this point that it really great and cool. With the new AVM2 (adobe virtual machine version 2) powering players above 9 one can really create wonders double/triple the times over the previous versions.
Initially i was a bit skeptical about getting into AS3 for my current projects i am working on are so Himalayan such that it would take a lot of time and energy to really convert it to support flash player9. Moreover i felt it was a great paradigm shift for someone like me for AS3 migration. Guru's out there have really started rocking with AS3, while a lot of children like me sitting here keep wondering about what's the deal in the new version of flash. I was also feeling that i am not doing my homework on learning AS3 for my current projects did not spare me the time for that but luckily and also daringly i thought of starting my new project based on AS3. Though it was a great risk but still was ready to face it.
Below i have mentioned a few areas where great changes have happened.

The new Class style :::::

Whenever we wanted to have more than one class file to share the same name serving different purpose but could not have it. In As3 they have introduced the concept of package naming culture as used in JAVA(but can you tell me what in Actionscript is not like JAVA?). This serves as a way to differentiate two classes sharing the same name but serving different purposes. Look below for an example.

An example of a AS3 class file

package com.mycompany.myprojectname.purposename;
     import requiredclasses.*;
     public class MyClass
            public function MyClass()

            public function doSomething():void






And now after the class is being written we can as usual import the package in the timeline and instantiate the variable the usual way as we do in AS2.0

Example ::::::

import com.mycompany.myprojectname.purposename.MyClass;

var mclass:MyClass =  new MyClass();



And now as we have now seen how the classes have changed to a class way we will now look at what has happened to our onPress, onRelease, onReleaseOutside etc.,


Handling Events ::::::

Before dwelling deep into the details we will now look at how we assigned mouse events to movieclips and buttons the AS-2.0 way.


       Example AS-2.0 ::::

       var mc:MovieClip = this.createEmptyMovieClip("mc",0);

       mc.onPress = function()


        trace("Hey i think a jerk pressed me");

        //output shows this message when pressed



 Example AS-3.0 ::::::

First create a rectangle and convert it to movieclip with the library name MyMc. Below are the screenshot's for your reference.



import flash.display.MovieClip;


var mc:MyMc = new MyMc();

function myMcClick(e:MouseEvent):void


   trace("Hey some jerk pressed me");





So this is the way we add actions to the new version of Flash.


Depth Management ::::::

Yeah this is the part i loved the most with AS-3.0. From the above example's code for AS-2.0 and 3.0 you would have noticed that there are some differences in the way we work with adding and assigning actions to MovieClips. The thing is that in the new version we have been spared the job of assigning the depth. You just need to use the keyword "addChild" which is a method in any MovieClip to add a childMovieClip.

Example ::::

//to create an MovieClip from the library.

var myMc:MyMc = new MyMc();



So how do we remove a MovieClip we added to the stage ????

Example :::::

//to create an EmptyMovieClip from the library.

var myMc:MyMc = new MyMc(); = ''foo';


//To remove this movieclip you have created.

this.removeChildAt(0);//where the number is the index.






Many more promising new things have come in the new version and i am at all loss of words to express it completely now. Better keep visiting my blog for there will be more updates,posts and learning's with what's new in AS-3.0.


Anonymous said...

Nice startup, you can start writing tutorial on AS3 so that beginners can also climb ladder along with you.

Ashok Srinivasan said...

Thanks anonymous for your interest and as per your request will try to post about whatever i know in AS1,2,3.


Ashok Srinivasan.

vishal said...

cool stuff it has helped me to startup with as 3........lookin forward for more and more