You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@flex.apache.org by SmileySnr <li...@dit.ie> on 2014/03/28 10:38:28 UTC

Global Variables

Due to the size of the script area in the my main project  mxml file, I
decided to break it up into several class files. One for each database
table. I have adopted a crude mechanism to move data around from the mxml to
the as scripts and between the as scripts. I have setup a class call
Globals, with an instance called g, which contains all a copy of all the
instance variables of the classes, Callresonder objects, datagrids etc. 

Resulting in 'g' being passed around every class in order to ensure the data
is available where it is needed.

I know I can create a new instance of the global variable within each class,
NOT quite what I want.

I would like to create the global variable in the main project mxml file and
reference it in the class files ...

Can this be done ?



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Global-Variables-tp5815.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.

Re: Global Variables

Posted by Martin Miko <ma...@gmail.com>.
Or make the Globals a singleton(ish) class, for ref. see [1]. All
approaches are valid and depend on what you want to build and how
maintainable it should be.

[1] http://www.swinburne.edu.au/design/tutorials/P-flash/T-How-to-build-a-Singleton-in-Actionscript-3/ID-143/

Martin


On Fri, Mar 28, 2014 at 10:57 AM, simon gladman <sg...@gmail.com> wrote:
> Well, the best way of doing it is to use a framework like Parsley. This
> gives you 'dependency injection' where you can inject a class into others -
> for example you might share a model across all your classes.
>
> The filthy way of doing it is to create a single globals class with all its
> variables made static :)
>
> Simon
>
>
> On 28 March 2014 09:38, SmileySnr <li...@dit.ie> wrote:
>
>> Due to the size of the script area in the my main project  mxml file, I
>> decided to break it up into several class files. One for each database
>> table. I have adopted a crude mechanism to move data around from the mxml
>> to
>> the as scripts and between the as scripts. I have setup a class call
>> Globals, with an instance called g, which contains all a copy of all the
>> instance variables of the classes, Callresonder objects, datagrids etc.
>>
>> Resulting in 'g' being passed around every class in order to ensure the
>> data
>> is available where it is needed.
>>
>> I know I can create a new instance of the global variable within each
>> class,
>> NOT quite what I want.
>>
>> I would like to create the global variable in the main project mxml file
>> and
>> reference it in the class files ...
>>
>> Can this be done ?
>>
>>
>>
>> --
>> View this message in context:
>> http://apache-flex-users.2333346.n4.nabble.com/Global-Variables-tp5815.html
>> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>>
>
>
>
> --
> *flexmonkey.co.uk <http://flexmonkey.co.uk> | @FlexMonkey
> <https://twitter.com/FlexMonkey> | +44 (0) 7973 669691*

Re: Global Variables

Posted by simon gladman <sg...@gmail.com>.
Well, the best way of doing it is to use a framework like Parsley. This
gives you 'dependency injection' where you can inject a class into others -
for example you might share a model across all your classes.

The filthy way of doing it is to create a single globals class with all its
variables made static :)

Simon


On 28 March 2014 09:38, SmileySnr <li...@dit.ie> wrote:

> Due to the size of the script area in the my main project  mxml file, I
> decided to break it up into several class files. One for each database
> table. I have adopted a crude mechanism to move data around from the mxml
> to
> the as scripts and between the as scripts. I have setup a class call
> Globals, with an instance called g, which contains all a copy of all the
> instance variables of the classes, Callresonder objects, datagrids etc.
>
> Resulting in 'g' being passed around every class in order to ensure the
> data
> is available where it is needed.
>
> I know I can create a new instance of the global variable within each
> class,
> NOT quite what I want.
>
> I would like to create the global variable in the main project mxml file
> and
> reference it in the class files ...
>
> Can this be done ?
>
>
>
> --
> View this message in context:
> http://apache-flex-users.2333346.n4.nabble.com/Global-Variables-tp5815.html
> Sent from the Apache Flex Users mailing list archive at Nabble.com.
>



-- 
*flexmonkey.co.uk <http://flexmonkey.co.uk> | @FlexMonkey
<https://twitter.com/FlexMonkey> | +44 (0) 7973 669691*

Re: Global Variables

Posted by Alex Harui <ah...@adobe.com>.
The other posts make good suggestions, but the simplest (and potentially
filthiest) is to declare public variables on the main app and reference
them from other classes via FlexGlobals.topLevelApplication.

-Alex

On 3/28/14 3:48 AM, "jfb" <j....@verizon.net> wrote:

>Hi,
>Look into use modules in Flex.
>http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf6908
>4-799a.html
>Best,
>
>
>
>--
>View this message in context:
>http://apache-flex-users.2333346.n4.nabble.com/Global-Variables-tp5815p581
>9.html
>Sent from the Apache Flex Users mailing list archive at Nabble.com.


Re: Global Variables

Posted by jfb <j....@verizon.net>.
Hi,
Look into use modules in Flex.
http://help.adobe.com/en_US/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-799a.html
Best,



--
View this message in context: http://apache-flex-users.2333346.n4.nabble.com/Global-Variables-tp5815p5819.html
Sent from the Apache Flex Users mailing list archive at Nabble.com.