-
Strange appearance of Error 1118
Hello All,
Usually, I know why and how to fix the compiler errors I receive, and I can fix the 1118 I'm currently receiving... but I don't really understand WHY I'm getting this particular error, and I want to make sure I do the right thing to correct it.
The scenario:
I have created a custom Global class and I essentially use it to store variables, constants and methods that just make sense to keep in a global scope.
I have another custom class called Navigator. The Navigator class extends another custom class which extends MovieClip.
Now, I want to basically store a reference to an instance of the Navigator class within the Global class so I can quickly have access to the Navigator instance from anywhere.
Here's what I initially tried in the Global class:
Actionscript Code:
public class Global{
public static var myNavigator:Navigator;
}
And the Navigator class:
Actionscript Code:
public class Navigator extends myOtherClass { public function Navigator() { Global.myNavigator = this; } }
And the error (apparently in Navigator.as):
Code:
1118: Implicit coercion of a value with static type my.custom.classes:Navigator to a possibly unrelated type Navigator.
Tell me oh sage-like Compiler Error Panel... how can Navigator be a "possibly unrelated type" to Navigator ??
Anyway, if I change the type declaration of myNavigator to an ancestor class like:
Actionscript Code:
public static var myNavigator:myOtherClass; // or even this public static var myNavigator:MovieClip;
I don't get the error anymore... but this doesn't seem like "good" code...
Should I be doing this differently?
Last edited by badaboom55; 03-30-2011 at 07:56 PM.
-
Senior Member
If you want to store a variable value, where the datatype is not always clear you should use a class with a public getter-setter and datatype Object. I do not completely understand what you have been doing and in which context, but the problem is a datatype problem as it looks like.
- The right of the People to create Flash movies shall not be infringed. -
-
Are you loading one swf into another? If so, you may have different ApplicationDomains which each have a definition of Navigator. Even if those definitions are identical, they are still separate. If this is the case, then make sure to use the same ApplicationDomain when loading the other swf.
-
Originally Posted by cancerinform
If you want to store a variable value, where the datatype is not always clear you should use a class with a public getter-setter and datatype Object. I do not completely understand what you have been doing and in which context, but the problem is a datatype problem as it looks like.
Well... I agree, but, the data type SHOULD be clear... I will always store a reference to an instance of Navigator in the Global.myNavigator variable... so, it's always been my impression that broadening the data type to more of a catch-all like Object, or MovieClip, instead of keeping the data type as specific as possible, is generally not "best-practice"?
At least, it makes troubleshooting more difficult because ANY Object, not just Navigators, would be valid. A getter/setter is probably the "right" way to do this... but I imagine I would still run up against the data type error.
-
Originally Posted by 5TonsOfFlax
Are you loading one swf into another? If so, you may have different ApplicationDomains which each have a definition of Navigator. Even if those definitions are identical, they are still separate. If this is the case, then make sure to use the same ApplicationDomain when loading the other swf.
No, I'm not loading SWFs...
But, it might have something to do with the way the Navigator gets instantiated?
I have an .fla with a Navigator instance already on the stage. I believe I want the variables in the Global class to be static, because I don't want to have to instantiate the Global class to use the properties and methods, etc.
Anyway, your response got me thinking, so in the Global class, I tried to put the entire package declaration in the data type:
Actionscript Code:
public static var myNavigator:my.custom.classes.Navigator;
It works... but I've never had to do this before... so it's a little worrisome.
Both the Global and Navigator classes are in the same package (my.custom.classes), and I tried various combinations of importing a type casting, but still got errors until I inserted the entire package path.
-
It's possible there was already something with the classname Navigator in your setup. I don't see anything in the usual flash packages, but if you are including a swc or something maybe. Or maybe it exists but is undocumented.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|