0

I would like know if and how is possible dynamically extends a class in AS2/3.
Something like:

public class Main extends getDefinitionByName("com.parent") as Class{...}

I know that this code is wrong, but just to show you what i need. Maybe with prototype?

user2054758
  • 321
  • 3
  • 18
  • 2
    Can you please describe a scenario where this would be useful? You would lose all static typing on your class. – Marty Dec 03 '14 at 22:15
  • when a project is splitted in a lot of swf files and you want use shared libs without increase project size – user2054758 Dec 03 '14 at 22:38
  • If you just want to share assets across files, you may want to take a look at [Runtime Shared Libraries](http://stackoverflow.com/questions/2070244/runtime-shared-libraries). – blvz Dec 03 '14 at 23:12
  • The answer to this question by the way is that you cannot do this in ActionScript 3 using the class system. You could emulate the class system with vanilla objects which inherit properties and methods from other objects in the same way the people write 'inheritance' in JavaScript. – Marty Dec 04 '14 at 00:26

1 Answers1

0

On AS2, it's easy:

trace("creating mc0");
this.attachMovie("libraryItemLinkage", "mc0", 0);

MovieClipPlus = function (){
  trace("hello world.");
};
MovieClipPlus.prototype = new MovieClip();
Object.registerClass("libraryItemLinkage", MovieClipPlus); 

trace("creating mc1");
this.attachMovie("libraryItemLinkage", "mc1", 1);

For AS3, it's not as simple as that. In fact, it's so complex (and slow), that it's easier to think of another way to accomplish what you are trying.

But if you still got the time and energy, take a look at the flash.utils.Proxy class, that will give you some new ideas.

Also, check these:

An introduction to proxies:
http://ltslashgt.com/2008/01/24/proxy-class-as3/

Dynamic proxy creation, with AS3 commons bytecode:
http://www.as3commons.org/as3-commons-bytecode/proxy.html

blvz
  • 1,335
  • 13
  • 15
  • in my case, "MovieClip" is an external class. Of course i can load it with getDefinitionByName("MovieClip") but what happen if "MovieClip" has static fields? – user2054758 Dec 06 '14 at 18:05