Home Tutorials Forums Articles Blogs Movies Library Employment Press
Old 06-25-2010, 09:46 AM   #1
kmasterzone
Registered User
 
Join Date: Apr 2010
Location: Ulhasnagar
Posts: 34
Default Accessing variable with String

ActionScript Code:
var constructVarNameForNoNotes:String="noNotesFor"+notesArray[i];                                 {constructVarNameForNoNotes}++;

The value which is stored in constructVarNameForNoNotes is "noNotesFor10" and noNotesFor10 is actually a label to which I want to set some text.

How can I access a variable with String.


Thanks.
kmasterzone is offline   Reply With Quote
Old 06-25-2010, 11:24 AM   #2
tadster
tadster
 
tadster's Avatar
 
Join Date: Feb 2009
Location: Texas
Posts: 2,111
Default

ActionScript Code:
//if noNotesFor10 is a variable in the same scope as constructVarNameForNoNotes, //meaning, if they have the same 'this' ..then: //.. var constructVarNameForNoNotes:String="noNotesFor"+notesArray[i]; //.. this[constructVarNameForNoNotes] = "somtext";
__________________
www.actiontad.com - ActionScript and JavaScript sitting in a tree...
tadster is offline   Reply With Quote
Old 06-25-2010, 07:30 PM   #3
drkstr
Flexpert
 
drkstr's Avatar
 
Join Date: Sep 2006
Location: Seattle, WA: USA
Posts: 1,587
Default

Building a numbered strings to create a "list" of items is considered very bad form. It is much better to use an actual list, and only use string accessors for dynamic variable references.

Example:

ActionScript Code:
private var _labelElementList:Array; private var _labelContentList:Array = ["One", "Two", "Three", "Four"]; override protected function createChildren():void {     super.createChildren();     //instantiate label items and add them as children     //if this component only has labels as children, then     //you do not need to keep a seperate array. Instead,     //use the function to access an indexed child IE     // this.getChildAt(0)     _labelElementList = [];     for( var i:int=0; i < _labelContentList.length; i++)     {         var label:Label = new Label();         _labelElementList.push(label);         this.addChild(label);     } } //copy the text values to your label elements override protected function commitProperties():void {     super.commitProperties();     for( var i:int=0; i < _labelContentList.length; i++)     {         var label:Label = Label( _labelElementList[i] );         var text:String = _labelContentList[i];         label.text = text;     } }
drkstr is offline   Reply With Quote
Reply


Thread Tools
Display Modes Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT. The time now is 04:14 AM.

///
Follow actionscriptorg on Twitter

 


Powered by vBulletin® Version 3.8.5
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Ad Management plugin by RedTyger
Copyright 2000-2013 ActionScript.org. All Rights Reserved.
Your use of this site is subject to our Privacy Policy and Terms of Use.