AS2 Cast and attach a Custom MovieClip class
One annoying thing that i found in as2 that has been fixed in as3 is the ability to write: new MyCustomClass() and then attach it to the stage. In AS2 there is no way to instantiate a class (which extends MovieClip) and have it parented to an existing MovieClip, unless you put it in the library with a linkage identifier, and assign the class to that asset. This is an arduous process if the clip doesn’t even require any assets drawn in the IDE.
A useful way to work around this is to have an empty movieClip in the library with a linkage of ‘empty’. Then to instantiate your custom class you must dynamically assign that class to the empty library asset with registerClass. If you then attach the ‘empty’ and cast it as your custom class type, bingo! you have your custom class instantiated on the stage.
registerClass( “empty”, MyCustomClass);
var mc:MyCustomClass = MyCustomClass(attachMovie(”empty”));
With correctly casting the attachMovie() you get correct typechecking and auto-completion in FlashDevelop. Remember, your custom class must extend MovieClip in the .as file
December 15th, 2008 at 1:21 am
Is this possible in flash timeline scripting?..i can’t get it to work
like this:
this.registerClass(”empty”, Circle);
var mcCircle:Circle = Circle(attachMovie(”empty”));
And the movieclip in lib has only a linkage indentifier right?
December 15th, 2008 at 1:25 am
To make the class Circle (as in this example) you will need to use AS2. Actually doing the registerClass and attachMovie - this should work fine on the timeline.
It definately works, i used to do this all the time - now i just use as3
September 10th, 2009 at 1:11 pm
Hi! I was surfing and found your blog post… nice! I love your blog.
Cheers! Sandra. R.
September 10th, 2009 at 4:14 pm
I love your site.
Love design!!! I just came across your blog and wanted to say that I?ve really enjoyed browsing your blog posts. Sign: ndsam
September 11th, 2009 at 3:43 pm
Sign: umsun Hello!!! rcuwwymhyw and 4765ssgfhphzye and 9518I like your blog. cool post!
January 30th, 2011 at 6:33 pm
I’m seriously not too acquainted with this matter but I do like to take a look at blogs for layout strategies and intriguing topics. You extremely described a subject matter that I generally do not care much about and made it fairly fascinating. That is a wonderful weblog that I will be aware of. I currently bookmarked it for future reference. Thank you Ccleaner, ccleaner news
February 21st, 2011 at 8:52 am
I genuinely prize your work , Great post.
June 8th, 2011 at 7:00 pm
I found this webpage on Google blogsearch and read a few of your different posts. This is one thing I’ve extremely wanted to be told more regarding I am finding it laborious to find trustworthy data regarding it, thus thank you for the useful post.
June 26th, 2011 at 12:53 am
I am definitely not as well accustomed to this subject matter but I do wish to visit blogs for layout ideas and exciting topics. You surely described a that I normally really don’t care considerably about and crafted it especially fascinating. That is a good weblog that I’ll be aware of. Find out tips in our site
July 9th, 2011 at 7:07 pm
Amazing! It’s like you comprehend my mind! A person seem to know so significantly relating to this, like you wrote the book in it or even something. We feel which you could do with a few pictures to drive the content house a little, on top of that, this is educational weblog publish. A excellent read. I’ll undoubtedly return.
November 25th, 2011 at 11:43 am
Legend!