Thank you all this makes sense now :)

This forum has helped me a lot thank you again!

--- In [email protected], "Gordon Smith" <[EMAIL PROTECTED]> wrote:
>
> > You cannot have *statements* outside of class methods.
>  
> Actually, you can, but it's unusual to do this. "Loose" statements in a
> class are executed at class initialization time, before any instances
> have been created. If pageRO and pageService were statics (i.e.,
> properties of the class itself), it would make sense. But since they are
> instance properties, it won't even compile.
>  
> - Gordon
> 
> ________________________________
> 
> From: [email protected] [mailto:[EMAIL PROTECTED] On
> Behalf Of Troy Gilbert
> Sent: Wednesday, February 14, 2007 9:51 PM
> To: [email protected]
> Subject: Re: [flexcoders] Re: Silly question? : Why do I have to create
> objects inside class functions?
> 
> 
> 
> 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] <mailto:[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]
> <mailto:flexcoders%40yahoogroups.com> , "rumpleminzeflickr" 
>       <rumpleminze@> wrote:
>       >
>       > They are declared in the format
>       > 
>       > public var pageService:PageService;
>       > 
>       > 
>       > --- In [email protected]
> <mailto: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]
> <mailto: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