Another option is to pass a reference to the entire parent scope into the as class.  That gives you access to any variable function in the parent.

 

A third option is to use Application.application to get to the main app scope.

 

Tracy

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of Nick
Sent: Monday, November 06, 2006 10:09 AM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] Re: Accessing Flex components via external actionscript - N00b Question :)

 

Hi John.

There are numerous amounts of ways to accomplish the scope you need.
After initial thought the way I would do it is pass your testInput to
your external class as a constructer parameter. In your constructor
equate this parameter to a local variable of that class.

ex.

Class MyCode {
private var localVar:TextInput;

public function MyCode(ptrInput:TextInput){
localVar = ptrInput;
}
public var testScope(){
localVar.text = "This is my text input component";
}

}
----------------------------------------------------------
In MXML:

<mx:Script>
import path.to.MyCode;

public var myclass:MyCode;


public function initApp(){
myclass = new MyCode(testInput);
myclass.testScope();
}

</mx:Script>
----------------------------------------------------------

Correct me if I am wrong but that should do it.

Hope that helps.

Nick
nickgs.com

--- In [EMAIL PROTECTED]ups.com, "mts_link" <john.cornett@...> wrote:
>
> Ok, I'm making the move from Flash/PHP to Flex 2, but have run into
> a "n00b" question and I have been unable to find an answer.
>
> When I use actionscript via the mx:Script tag IN the mxml file, I can
> access the components without much problem.
>
> Example:
> public function getTestInput()
> {
> trace("Value of Text Input: " + testInput.text);
> }
>
> In the MXML page I have a text input with an id of testInput. The
> moment I move this same code into an external actionscript class, I
> can no longer access this variable.
>
> I know, it certainly has to do with scope, but how do I directly
> access the mxml components from within my external actionscript
> class? I have seen mention of parentDocument and parentApplication,
> but I cannot seem to get this to work for me.
>
> Can anyone shed some light on this and perhaps provide an example, or
> a link to an example?
>
> Thanks!
>
> John Cornett
>

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to