Re: [flexcoders] Re: Simplfying Repetitive Code

2010-01-11 Thread Tibor Ballai

Hi Guys,

This discussion inspired me to write an article about the dynamic 
elements of the language.
It took a while to finish but after nearly a month I found enough time 
to wrap it up.


http://tiborballai.com/blog/2010/1/11/dynamic-elements-of-the-actionscript-3-language.html


Tibor.

www.tiborballai.com

invertedspear wrote:
 


Tibor,
I have been needing something like 'this["string"+var]' for awhile. 
Would have saved me a lot of time to know about that sooner. Thanks.

~Mike






[flexcoders] Re: Simplfying Repetitive Code

2009-12-16 Thread invertedspear
Tibor,
I have been needing something like 'this["string"+var]' for awhile. Would 
have saved me a lot of time to know about that sooner. Thanks.
~Mike



[flexcoders] Re: Simplfying Repetitive Code

2009-12-16 Thread mitchgrrt


private var seriesArray:Array = 
  [series1, series2, series3, series4, series5 ];// etc.

private function changeSeries():void {
  for each (var series:Object in seriesArray) {
series.yField = 'male';
  }
}

I haven't tried to compile it and run but it should work.

--- In flexcoders@yahoogroups.com, "AJC2357"  wrote:
>
> Hi all, 
> 
> If I have a function like this.
> 
> private function changeSeries(): void {
> series1.yField = 'male';
> series2.yField = 'male';
> series3.yField = 'male';
> series4.yField = 'male';
> series5.yField = 'male';
> series6.yField = 'male';
> series7.yField = 'male';
> series8.yField = 'male';
> series9.yField = 'male';
> series10.yField = 'male';
> }
> 
> Is there an easy way to simplify it?  Something like
> 
> private function changeSeries(): void {
> "something to indicate i equaling zero through ten"
> series[i] = 'male';
> }
> 
> Any code help would be much appreciated!
> 
> Alex
>



[flexcoders] Re: Simplfying Repetitive Code

2009-12-16 Thread Tibor
You are welcome.

Be careful though, if you are using the array access notation, the compiler 
won't be able to catch any mistakes you might make.

For instance, this["series11"].yField = 'male'; will compile without errors, 
even if you don't have a series11 property, but you will receive a run-time 
error when the code is executed.

Tibor.

www.tiborballai.com


--- In flexcoders@yahoogroups.com, "AJC2357"  wrote:
>
> Thanks so much, Tibor.
> 
> This structure - this["series"+i] - was what I needed!
> 
> --- In flexcoders@yahoogroups.com, "Tibor"  wrote:
> >
> > Hi Alex,
> > 
> > You can use a for loop.
> > 
> > for (var i:uint=1; i<=10; i++){
> >   this["series"+i].yField = 'male';
> > }
> > 
> > Hope this helps,
> > 
> > Tibor.
> > 
> > www.tiborballai.com
> > 
> > --- In flexcoders@yahoogroups.com, "AJC2357"  wrote:
> > >
> > > Hi all, 
> > > 
> > > If I have a function like this.
> > > 
> > > private function changeSeries(): void {
> > > series1.yField = 'male';
> > > series2.yField = 'male';
> > > series3.yField = 'male';
> > > series4.yField = 'male';
> > > series5.yField = 'male';
> > > series6.yField = 'male';
> > > series7.yField = 'male';
> > > series8.yField = 'male';
> > > series9.yField = 'male';
> > > series10.yField = 'male';
> > > }
> > > 
> > > Is there an easy way to simplify it?  Something like
> > > 
> > > private function changeSeries(): void {
> > > "something to indicate i equaling zero through ten"
> > > series[i] = 'male';
> > > }
> > > 
> > > Any code help would be much appreciated!
> > > 
> > > Alex
> > >
> >
>




[flexcoders] Re: Simplfying Repetitive Code

2009-12-16 Thread AJC2357
Thanks so much, Tibor.

This structure - this["series"+i] - was what I needed!

--- In flexcoders@yahoogroups.com, "Tibor"  wrote:
>
> Hi Alex,
> 
> You can use a for loop.
> 
> for (var i:uint=1; i<=10; i++){
>   this["series"+i].yField = 'male';
> }
> 
> Hope this helps,
> 
> Tibor.
> 
> www.tiborballai.com
> 
> --- In flexcoders@yahoogroups.com, "AJC2357"  wrote:
> >
> > Hi all, 
> > 
> > If I have a function like this.
> > 
> > private function changeSeries(): void {
> > series1.yField = 'male';
> > series2.yField = 'male';
> > series3.yField = 'male';
> > series4.yField = 'male';
> > series5.yField = 'male';
> > series6.yField = 'male';
> > series7.yField = 'male';
> > series8.yField = 'male';
> > series9.yField = 'male';
> > series10.yField = 'male';
> > }
> > 
> > Is there an easy way to simplify it?  Something like
> > 
> > private function changeSeries(): void {
> > "something to indicate i equaling zero through ten"
> > series[i] = 'male';
> > }
> > 
> > Any code help would be much appreciated!
> > 
> > Alex
> >
>




[flexcoders] Re: Simplfying Repetitive Code

2009-12-16 Thread invertedspear
simple for loop would do it:

for(var i:int=1; i<=10;i++){
 
}

--- In flexcoders@yahoogroups.com, "AJC2357"  wrote:
>
> Hi all, 
> 
> If I have a function like this.
> 
> private function changeSeries(): void {
> series1.yField = 'male';
> series2.yField = 'male';
> series3.yField = 'male';
> series4.yField = 'male';
> series5.yField = 'male';
> series6.yField = 'male';
> series7.yField = 'male';
> series8.yField = 'male';
> series9.yField = 'male';
> series10.yField = 'male';
> }
> 
> Is there an easy way to simplify it?  Something like
> 
> private function changeSeries(): void {
> "something to indicate i equaling zero through ten"
> series[i] = 'male';
> }
> 
> Any code help would be much appreciated!
> 
> Alex
>




[flexcoders] Re: Simplfying Repetitive Code

2009-12-16 Thread Tibor
Hi Alex,

You can use a for loop.

for (var i:uint=1; i<=10; i++){
  this["series"+i].yField = 'male';
}

Hope this helps,

Tibor.

www.tiborballai.com

--- In flexcoders@yahoogroups.com, "AJC2357"  wrote:
>
> Hi all, 
> 
> If I have a function like this.
> 
> private function changeSeries(): void {
> series1.yField = 'male';
> series2.yField = 'male';
> series3.yField = 'male';
> series4.yField = 'male';
> series5.yField = 'male';
> series6.yField = 'male';
> series7.yField = 'male';
> series8.yField = 'male';
> series9.yField = 'male';
> series10.yField = 'male';
> }
> 
> Is there an easy way to simplify it?  Something like
> 
> private function changeSeries(): void {
> "something to indicate i equaling zero through ten"
> series[i] = 'male';
> }
> 
> Any code help would be much appreciated!
> 
> Alex
>