Ok, if your class is a component, and has been added to the display list
(as a child of the main class), you can reference a public variable in
the parent class with either outerDocument.myVariable or
parentDocument.myVariable.  Personally, I don't like this kind of
dependency, and recommend creating a getter/setter variable in the class
and set it after the class is instantiated and, if needed, when the main
variable is changed.   A getter/setter is recommended for the top level
variable as well.  This way your class can initialize it's own state, if
desired have it's state changed by the parent, and become re-usable;
without depending on the parent.

-TH

--- In [email protected], "Tim Hoff" <timh...@...> wrote:
>
>
> :: waits for Paul ::
>
> :)
>
> -TH
>
> --- In [email protected], - - sailorsea21@ wrote:
> >
> > How about the other way around, how can I access a variable in my
main
> mxml from my class package?
> >
> > Thanks!
> >
> >
> >
> > ________________________________
> > From: Tim Hoff TimHoff@
> > To: [email protected]
> > Sent: Monday, April 6, 2009 1:50:24 PM
> > Subject: [flexcoders] Re: How can I call a function from a class?
> >
> >
> >
> > There's a couple of ways. If your class and function are static,
like
> a
> > utility class that doesn't persist any data, just call
> > Layout.traceTest( ); Note: Classes should be capitalized, in order
to
> > differentiate them from variables. Another way is to instantiate the
> > class as a variable:
> >
> > private function callClassFunction( ):void
> > {
> > var layout:Layout = new Layout();
> > layout.traceTest( );
> > }
> >
> > -TH
> >
> > --- In flexcod...@yahoogro ups.com, "sailorsea21" <sailorsea21@ ...>
> > wrote:
> > >
> > > Hi everyone, How can I call a function from a class?
> > >
> > > ////// MAIN FILE
> > > import test.layout;
> > >
> > > private function callClassFunction( ):void
> > > {
> > > test.layout_ QT.traceTest( );
> > > }
> > >
> > >
> > >
> > > ////// CLASS FILE layout.as
> > > package test
> > > {
> > > public class layout
> > > {
> > > public function traceTest(): void
> > > {
> > > trace("This is a test.");
> > > }
> > > }
> > > }
> > >
> > > Thanks.
> > >
> >
>



Reply via email to