I thought it was too (didn't check the existence of _instance), but I was
sure the class was initialized and _instance != null, since it's a document
class, and even after I changed the code, it keeps giving me the error, and
the really weird thing is, it works if I declare a dummy variable, with
]
To: Flash Coders List flashcoders@chattyfig.figleaf.com
Sent: Monday, November 24, 2008 1:05 PM
Subject: Re: [Flashcoders] singleton returns null
I thought it was too (didn't check the existence of _instance), but I was
sure the class was initialized and _instance != null, since it's a document
class
Hi,
im not sure about your syntax.
This:
class MyClass {
public static var _instance:MyClass = this;
}
will not work.
You are looking for something like:
class MyClass {
public static var _instance:MyClass = null;
public function MyClass () {
_instance = this;
}
}
Although
Hello list,
I've been having a question since a time ago... I'm using a flash framework
within my websites (Gaia), and between the classes, I use some singleton
pattern to communicate between them. This way, theorically, I can get any
class instance from another, and I don't need to know the path
Hello,
About the syntax, I meant the second one, actually, declare the _instance
just in constructor, but I just noticed a very weird thing...When I get null
as I was referencing, if I just declare in my main class, a var casting the
type of class that was returning null, it'll work. Seems
Hi Fabio,
could you maybe post 2 examples, one that works, and one that doesn't?
A picture says more than a thousand words:)
greetz
JC
On Fri, Nov 21, 2008 at 2:19 PM, Fabio Pinatti [EMAIL PROTECTED] wrote:
Hello,
About the syntax, I meant the second one, actually, declare the _instance
Sure thing!
In my main document class, I have
class BaseClass {
public function BaseClass() {
}
}
I have a second document class, that is loaded inside the first one.
class SecondClass {
public static var _instance:SecondClass;
public function SecondClass() {
Hmmm... I'm not sure I can pinpoint exactly where the problem is in your
code. But there is some weirdness there around where and how that _instance
variable of yours is getting instantiated. It seems like there's nothing to
enforce it only gets created once or doesn't get overwritten multiple
Fábio,
The reason you are seeing null is because your getInstance() does not assign
the instance of SecondClass to _instance if it hasn't already been
instantiated:
public static function getInstance():SecondClass {
return _instance; //_instance has never been assigned
9 matches
Mail list logo