Not exactly right...

The problem is that what you're wanting to do is execute an assignment
statement. You cannot have *statements* outside of class methods.

What you can do is have *initializers* as part of *declarations*. So, you
can do this:

public class MyClass
{
   public var myVar:String = "some text";
   public var myOtherVar:Singleton = Singleton.getInstance();
}

You have to make the assignment at the point where you declare the variable
(so it actually becomes what is called an "initializer").

The initialization statement will be executed as part of the constructor's
prologue (immediately before you constructor code is called), i.e. when you
call "new MyClass();".

Troy.


On 2/14/07, helihobby <[EMAIL PROTECTED]> wrote:

  I re-read your question and the answer is no you can not.
The reason is becuase Flex is event driven.

What you can do is add to the Application tag flag of:

creationComplete="init()"

and use inside the class:

public function init():void{

pageRO = new RemoteObject();
pageService = PageService.getInstance();

}

--- In [email protected] <flexcoders%40yahoogroups.com>,
"rumpleminzeflickr"
<[EMAIL PROTECTED]> wrote:
>
> They are declared in the format
>
> public var pageService:PageService;
>
>
> --- In [email protected] <flexcoders%40yahoogroups.com>,
"helihobby" <helihobby@> wrote:
> >
> > I think you forgot to add var unless you define a private var at
the
> > top.
> >
> >
> > --- In [email protected] <flexcoders%40yahoogroups.com>,
"rumpleminzeflickr"
> > <rumpleminze@> wrote:
> > >
> > > Hi,
> > >
> > > This maybe a really dumb question, but why I can't I create new
> > > objects or even assign a null object a value in the class
itself?
> > >
> > > It works fine if I do it in a function. Just trying to
understand
> > i'm
> > > sure there is a good reason.
> > >
> > > Many thanks,
> > >
> > >
> > >
> > >
> > > public class MyClass
> > > {
> > >
> > > // doesn't work here
> > > pageRO = new RemoteObject();
> > > pageService = PageService.getInstance();
> > >
> > >
> > > public function Foo():void{
> > >
> > > // works here
> > > pageRO = new RemoteObject();
> > > pageService = PageService.getInstance();
> > >
> > > }
> > > }
> > >
> >
>

Reply via email to