Some basics of Actionscript 3.0

I just come from an interview and could not answer appropriately some basic questions. I have tried them at home and putting all those in one example here. I have a flash project structure as below
com package
class One
comm package
class One

Now the problem is what happens when you want to make an object of  “One”, which class gets instantiated? Though my answer was “the nearest to the application class”, but which one is nearer?!! Well, what I found is, the order of import statement does the trick. The one imported first will be instantiated.

import flash.display.MovieClip;

import comm.One;
import com.One;

public class Main extends MovieClip{
public function Main(){
var myObj:One=new One();//This depends upon the import statements, the object will be of the first imported CLASS


If we alter the import statement, I mean if we import “com.One” first and then “comm.One”, the result will be a “One” Object of packge “com”.Well then if we want a specified object then have to write the full path as
var myObj:*=new com.One();
var myObject:*=new comm.One();

This reminded of me Colin Moock’s Essential Actionscript 3.0 book. I must read it again.

Another intersting question is what happens when
what would be the trace?

It throws an error
ReferenceError: Error #1056: Cannot create property 0 on Number.
at Main$iinit()
This happens at a[0][0]=2;
The correct would be
Now lets see what happens when we do like this
var arr:Array=[];
trace(‘Array trace2 : ‘,arr.length,arr[0]);
The length will be 10 and all the other indixes will have “undefined” values.

A lot of basics to be aware of.As a note I keep this, to experiement these kind of fun stuffs whenever I get some time.


10 thoughts on “Some basics of Actionscript 3.0

  1. Those are tricky questions – I don’t think entirely appropriate for an interview. Who really knows which One class really gets instantiated? I would have thought your example would have caused an ambiguous error, but looks like I would have been wrong too if it ended up being the first one imported. The truth is, if there’s a conflict, you should always use the fully qualified class name when making instances and not rely on import order.

    And the array thing is a very common mistake, even for seasoned developers. Its not that people think it should work; its just easy to overlook. I can tell you a few times I’ve been looking at code trying to figure out the error when it was right there in front of me – OH, right, we forgot to instantiate the array in the 2nd dimension.

  2. hi buddy,
    I never thought you are reading my blog !! For me, you guys are inspirations. I am overwhelmed and feel great about that. This obviously gives me more enthusiasm to blog and express myself.Thanks for it.

  3. Actually, I believe the class instantiation question is ENTIRELY appropriate for an interview. The reason is because I want to hear from my interviewee that it is a dumb way to name your classes and a poor way to architect an application. Then, I want to hear that if you are forced into that position by inheriting the code of a moron, that you know that you instantiate by using the package path

    new com.comm.One();

    AND that you do not like that architecture.

    Programmers SHOULD be opinionated. I don’t know a single great coder that isn’t. That doesn’t mean you shouldn’t be willing to learn new things, or be too stubborn to learn things that are in direct opposition to your currently held beliefs, just that you should have convictions about coding in general. It shows passion, resourcefulness, determination and that you care about coding.

    On the array thing, that’s just a simple syntax question. If I was going to put that in an interview, I would embed that syntax mistake in a bunch of other code and ask the developer to tell me why this code throws an error without knowing which line is at fault.

  4. I agree with Senocular, those are insignificant interview questions. I’d hire you regardless based on the fact you cared enough to blog how to do something you didn’t know, and learned to do.

  5. wow, some more inspirations commenting in it too. Thanks guys, I never realized until this post that I am being read !!! Thanks and I hope it will go in my blood to code more and blog more.

  6. Hi Saumya,

    It was really awesome, never thought of dis…
    thanks a lot!
    waiting for more…

    Thanks & Regards
    Sagar Wadke

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s