LOL. "How about the other way around, how can I access a variable in my main mxml from my class package?"
Well, the real answer is you shouldn't do it. You really don't want to build dependencies between your classes (unless there's a really good reason) or between a class and your application. A really bad way to do what you're asking: <?xml version="1.0" encoding="utf-8"?> <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="doIt()"> <mx:Script> <![CDATA[ var s:String="ABC"; function doIt():void { Application.application.s+="..DEF"; txtFld.text=s; } ]]> </mx:Script> <mx:Text id="txtFld" text="UNSET" /> </mx:Application> The Application class has a static attribute application that refers to the application scope. Please don't use it without a really good reason. Really speaking most people issue events inter-class communication (without building inter-dependencies), or would pass the variable as a parameter. If the variable being passed is an object reference, you can still update the value when it's passed as a parameter. Other techniques people use - static class variables - accessible without instance declaration. I think there's something else I've forgotten. It's late! Paul ----- Original Message ----- From: "Tim Hoff" <[email protected]> To: <[email protected]> Sent: Monday, April 06, 2009 8:08 PM Subject: [flexcoders] Re: How can I call a function from a class? > > :: waits for Paul :: > > :) > > -TH > > --- In [email protected], - - <sailorse...@...> 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 timh...@... >> 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. >> > >> > > > > > > ------------------------------------ > > -- > Flexcoders Mailing List > FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt > Alternative FAQ location: > https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847 > Search Archives: > http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! Groups > Links > > >

