View Full Version : Proxy subclass: unable to implement interface
wvxvw
March 26th, 2009, 11:54 AM
Basically, what I want is to have a class that:
- extends Proxy.
- implements IEventDispatcher.
- has property "addEventListener" (it will also have this method).
or at least will trigger getProperty as a fallback when somebody tries to improperly access addEventListener...
skineh
March 26th, 2009, 02:59 PM
Basically, what I want is to have a class that:
- extends Proxy.
- implements IEventDispatcher.
- has property "addEventListener" (it will also have this method).
or at least will trigger getProperty as a fallback when somebody tries to improperly access addEventListener...
Hmmm... that's a tough one. By declaring addEventListener for IEventDispatcher, you're pretty much guaranteeing an illegal assignment error if you try to access it as a property (the public function addEventListener will take precedent over getProperty). And adding it as a class-level property will just get you all kinds of incompatible override errors. Not sure you could get this to cooperate. :/
senocular
March 26th, 2009, 04:38 PM
yeah, I think the interface pretty much enforces the fact that addEventListener must exist as a publicly accessible, class-defined member.
Krilnon
March 26th, 2009, 04:45 PM
Do you need the class to be an IEventDispatcher? Maybe you've already thought of this, but unless you're passing the class to something that checks the type of the class you pass it, you can probably get away without using the interface and simply taking advantage of Proxy's callProperty or whatever.
skineh
March 26th, 2009, 04:50 PM
yeah, I think the interface pretty much enforces the fact that addEventListener must exist as a publicly accessible, class-defined member.
Yeah, there's no escaping that. It just then makes it impossible to intercept addEventListener being used as a property via Proxy's getProperty/setProperty. Looks like defining the method ensures the compiler will always look at that rather than callProperty, etc.
A shame, too, since I can see what you're looking to do wxvxw, and I think it'd be great to catch misuse of the method (ala trying to access as a property). I'm sure you've already considered it, but would the project this is for allow for something not as user-friendly? Like just keeping an instance of EventDispatcher in the Proxy extended class and then accessing it through callProperty/getProperty/setProperty, but then wherever you need to pass the object that requires it to implement IEventDispatcher you pass it the instance? Like...
var pDispatcher:ProxyDispatcher = new ProxyDispatcher();
pDispatcher.addEventListener(Event.COMPLETE, done); // Handled by callProperty
pDispatcher.addEventListener = someFunction // Handled by setProperty
someMethod(pDispatcher.dispatcher); // Actual EventDispatcher instance
...
function someMethod(dispatcher:IEventDispatcher) {
Not as elegant, sadly... :(
skineh
March 26th, 2009, 04:54 PM
Do you need the class to be an IEventDispatcher? Maybe you've already thought of this, but unless you're passing the class to something that checks the type of the class you pass it, you can probably get away without using the interface and simply taking advantage of Proxy's callProperty or whatever.
Yeah, I'm working under the assumption that you'll need to pass it to something that's going to check against IEventDispatcher. Obviously if that's not the case then just don't implement. :D But you're a bright guy so I'm guessing it was implied that you needed the interface implemented.
wvxvw
March 26th, 2009, 05:47 PM
I can let it not be an IEventDispatcher, but, that'd mean I'll have some wrapper class for it and I won't be able to use it with data binding in Flex :( and it was my original goal... But this also means I cannot really even make it an MXML component just because it requires implementing an interface too, only 1 method though, but, still...
The last thing I hoped for that you can implement interface methods on AS3 namespace :) but, no way! Even though it's a by-default open namespace, it won't allow me to do it :)
wvxvw
March 27th, 2009, 08:33 AM
With the help from badun (http://www.flasher.ru/forum/member.php?u=50321) and a_[w] (http://actualwave.com/blog/?p=25), I've found this:
http://www.docsultant.com/site2/articles/flex_internals.html#xmlNotify
So, now I feel a little bit stupid trying to implement that myself :) But, hey, at least it is doable!
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.