03-03-2010, 09:02 PM
|
#1
|
|
|
overwriting methods with custom namespaces
Can methods declared with a custom namespace be overwritten?
Code:
// secret.as
package {
public namespace secret = "http://www.example.com/secret";
}
// Base.as
package {
import secret;
public class Base {
public function Base() {
}
secret function test():void {
trace("Base test");
}
}
}
// Extended.as
package {
import secret;
public class Extended extends Base {
public function Extended() {
}
override secret function test():void {
trace("Extended test2");
}
}
}
If I try the above I get "1004: Namespace was not found or is not a compile-time constant."
If I remove override I get "VerifyError: Error #1053: Illegal override of test in Extended."
Is this not possible? Is there a workaround? Thanks.
|
|
|
03-04-2010, 05:32 PM
|
#5
|
|
|
Hi, namespaces are resolved by their URI, so, if you know, what is the URI value, you can declare a namespace inside your other class and use that declaration, you don't have to import anything.
I.e.:
Code:
public namespace foo = "flash.display";
// and
public namespace foobar = "flash.display";
// will target the same object
trace(foo::["MovieClip"], foobar::["MovieClip"]);
// [class MovieClip] [class MovieClip]
|
|
|
03-04-2010, 06:54 PM
|
#6
|
|
|
Quote:
Originally Posted by IqAndreas
Is that exactly how your code is written out when you tested it? Or is it just a stripped down version?
|
Exact code. Testing small case to isolate the bugs.
|
|
|
03-04-2010, 06:55 PM
|
#7
|
|
|
Ok, I got rid of the namespace class and instead explicitly declared the namespace in both my Base and Extended classes. This worked! Thanks.
Code:
// Base.as
package {
public class Base {
private namespace secret = "http://www.example.com/secret";
public function Base() {
}
secret function test():void {
trace("Base test");
}
}
}
// Extended.as
package {
public class Extended extends Base {
private namespace secret = "http://www.example.com/secret";
public function Extended() {
}
override secret function test():void {
trace("Extended test2");
}
}
}
I don't really see much use in creating classes only for defining namespaces if they don't work with something as core as overriding methods. I thought I was following best practices by only defining the namespace once. I guess not. Thanks again!
Last edited by oopstoons; 03-04-2010 at 07:01 PM..
|
|
|
03-04-2010, 08:08 PM
|
#8
|
|
|
oopstoons:
No-no-no-no, you were thinking correctly, and, actually, that what should've happen, but, practically it doesn't happen like that all the time... some compiler quirks. Could be that in next version of compiler it will get fixed, or, maybe it's already fixed and you just have to get that new version. I think it inconsistently happened to me now and then, so, I "discovered" this workaround, but, normally, you shouldn't be needing it.
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
All times are GMT -4. The time now is 11:27 PM.
|
|