this is not possible at the moment. A possible implementation had to go through all types in _global and check whether the class implements the type. This would be rather slow.
But if you really need it I can add a getImplementedInterfaces method until the next release (this weekend).
Greetings,
Simon
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
where implements_function implements all the function of 'abstract1' and 'abstract2' classes in the 'this' class.
If I can see all the interfaces implemented, I can simply do: this->implements_function();
Thanks for the help.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to have a class foo2 that extends foo at runtime. For example:
in the case:
foo3->foo2->foo (foo3 extends foo2 that extends foo)
if I'd like to instantiate _only_ one object of foo3 that inherit form fooNew like:
foo3->foo2->fooNew
(while keeping the old foo3 in other instances in the movie)
I have to rewrite all the classes, increasing the swf size.
In more complex scenarios there can be many classes.
My idea is to create a copy at runtime of every class that I need to modify, and then change their __proto__
I understand now. You confused me because you said interface, but apparantly you are not using any interfaces but classes. ;) (which of course have the implementation)
But why would you wanna do something like that? Use polymorphism in such a case. foo3 extends foo2 and a foo3 instance holds a reference to an instance of foo or fooNew.
I have written some code and I never needed to copy whole classes. :D
instance is not an instance of foo2New because foo3New.prototype.__proto__ is not set to foo2New.prototype because of a restriction introduced by ASSetPropFlags.
It is strange because 6 give the write permission to the properties I try to overwrite but 'lock' the __proto__ property.
Let me explain what I'm trying to do: what I cannot do with composition is to easly extend basic movieclip propertyes/method like onPress or _x, _y.
To do that I need to extend. For example:
class Window that extends Resizable and Movable and Selectable.
class Button extends Allignable and Selectable.
Every class is a little 'behaviour' that implements some method like onPress or onEnterFrame
For now I've managed to 'copy' the entire class except for the costructor and to build the complete extension chain.
There is a way to copy the costructor?
Thanks.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
you could make Resizable, Movable, Selectable, Allignable etc. to interfaces and offer some utils to delegate the behavior to.
Example:
class Window extends MovieClip implements Resizable, Movable, Selectable {
private var resizeStrategy:ResizeStrategy;
public function Window(Void) {
resizeStrategy = new AbsoluteResizingStrategy(this);
// RelativeResizingStrategy, ...
}
public function resize(width:Number, height:Number):Void {
resizeStrategy.resize(width, height);
}
}
A more light-weight solution may be: ResizeStrategy.resizeAbsolut(width, height), .resizeRelative(width, height), ...
I think that extending is in your case not appropriate. Because Resizable is not (does not extend) Movable and Movable is not Selectable, but the Window is resizable, movable and selectable, and does implements the appropriate interfaces.
The constructor is simply a method like any other that is held in _global. For example _global.org.as2lib.core.BasicClass is the BasicClass constructor. You can for example override it, execute it as a normal method or wrap it, but you can of course not copy it, as you cannot copy a function, but a wrapping constructor could invoke the original constructor as normal method or do something like this.apply(originalConstructor, arguments).
But I suggest you to not do these kinds of things, because your code will become pretty messy and un-managable.
I just remembered that there is a AccessPermission class in the as2lib that uses the ASSetPropFlags. To allow everything to be done with the object's variables you have to use the value 0, not 6. The ASSetPropFlags pic on FlashGuru seems to be wrong (or the behaviour has changed since Flash 7). It should say "cannot overwrite" and "cannot delete".
Simon
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Can I see all the implemented interfaces in a class at runtime with ReflectUtil?
Hi Marco,
this is not possible at the moment. A possible implementation had to go through all types in _global and check whether the class implements the type. This would be rather slow.
But if you really need it I can add a getImplementedInterfaces method until the next release (this weekend).
Greetings,
Simon
Thanks,
do you mean something like:
if (Type(class) != null)
for all the types in _global? Can searching only in a specified package be faster?
What I need to do is something like mx.events.EventDispatcher.initialize() do:
this->implements_function('abstract1', 'abstract2');
where implements_function implements all the function of 'abstract1' and 'abstract2' classes in the 'this' class.
If I can see all the interfaces implemented, I can simply do: this->implements_function();
Thanks for the help.
Hi Marco,
if you know the package searching only in that package is of course much faster.
But I do not get what you are trying to do. How does the implementFunction method how the implementation looks like?
Simon
I'm trying to have a class foo2 that extends foo at runtime. For example:
in the case:
foo3->foo2->foo (foo3 extends foo2 that extends foo)
if I'd like to instantiate _only_ one object of foo3 that inherit form fooNew like:
foo3->foo2->fooNew
(while keeping the old foo3 in other instances in the movie)
I have to rewrite all the classes, increasing the swf size.
In more complex scenarios there can be many classes.
My idea is to create a copy at runtime of every class that I need to modify, and then change their __proto__
I've do this function:
function classCopy(src) {
ASSetPropFlags(src.prototype,null,6,true);
dst = function() { trace("Temp costructor"); };
ASSetPropFlags(dst.prototype,null,6,true);
for(i in src.prototype){
trace("implments: " + i);
dst.prototype[i] = src.prototype[i];
}
return dst;
}
//I do:
foo3New = classCopy(foo3);
foo2New = classCopy(foo2);
foo3New.prototype.__proto__ = foo2New.prototype;
foo2New.prototype.__proto__ = fooNew.prototype;
instance = new foo3New();
sadly instance doesn't extends foo2New, I am missing somthing?
Thanks.
I understand now. You confused me because you said interface, but apparantly you are not using any interfaces but classes. ;) (which of course have the implementation)
But why would you wanna do something like that? Use polymorphism in such a case. foo3 extends foo2 and a foo3 instance holds a reference to an instance of foo or fooNew.
I have written some code and I never needed to copy whole classes. :D
instance is not an instance of foo2New because foo3New.prototype.__proto__ is not set to foo2New.prototype because of a restriction introduced by ASSetPropFlags.
trace(foo3New.prototype.__proto__ == foo2New.prototype); // returns false
But if you document the following out it will work:
//ASSetPropFlags(dst.prototype, null, 6, true);
6 seems to be the wrong value. I do myself not know the value at the moment (I cannot find the list were the different values were explained).
Greetings,
Simon
Many thanks for the answer.
Excuseme, I haven't explained me well in my first post :)
You can see the values of ASSetPropFlags here: http://www.flashguru.co.uk/assetpropflags/
It is strange because 6 give the write permission to the properties I try to overwrite but 'lock' the __proto__ property.
Let me explain what I'm trying to do: what I cannot do with composition is to easly extend basic movieclip propertyes/method like onPress or _x, _y.
To do that I need to extend. For example:
class Window that extends Resizable and Movable and Selectable.
class Button extends Allignable and Selectable.
Every class is a little 'behaviour' that implements some method like onPress or onEnterFrame
For now I've managed to 'copy' the entire class except for the costructor and to build the complete extension chain.
There is a way to copy the costructor?
Thanks.
Hi Marco,
you could make Resizable, Movable, Selectable, Allignable etc. to interfaces and offer some utils to delegate the behavior to.
Example:
class Window extends MovieClip implements Resizable, Movable, Selectable {
private var resizeStrategy:ResizeStrategy;
public function Window(Void) {
resizeStrategy = new AbsoluteResizingStrategy(this);
// RelativeResizingStrategy, ...
}
public function resize(width:Number, height:Number):Void {
resizeStrategy.resize(width, height);
}
}
A more light-weight solution may be: ResizeStrategy.resizeAbsolut(width, height), .resizeRelative(width, height), ...
I think that extending is in your case not appropriate. Because Resizable is not (does not extend) Movable and Movable is not Selectable, but the Window is resizable, movable and selectable, and does implements the appropriate interfaces.
The constructor is simply a method like any other that is held in _global. For example _global.org.as2lib.core.BasicClass is the BasicClass constructor. You can for example override it, execute it as a normal method or wrap it, but you can of course not copy it, as you cannot copy a function, but a wrapping constructor could invoke the original constructor as normal method or do something like this.apply(originalConstructor, arguments).
But I suggest you to not do these kinds of things, because your code will become pretty messy and un-managable.
I just remembered that there is a AccessPermission class in the as2lib that uses the ASSetPropFlags. To allow everything to be done with the object's variables you have to use the value 0, not 6. The ASSetPropFlags pic on FlashGuru seems to be wrong (or the behaviour has changed since Flash 7). It should say "cannot overwrite" and "cannot delete".
Simon
Thank you so much for the help and the suggestion :)
I've found the AccessPermission class and I'll use it.
I will keep searching for a nice way extends the behaviour of my UI classes.
Goodby :)