[BNM] Converting string to variable name (Flash)

Ali ali at nubz.com
Mon Apr 10 12:23:06 BST 2006


You are declaring commenttext as a string literal!

If this script is sitting on the root timeline try:

var comment1:String = "1 - text for 1st comment.";
var comment2:String  = "2 - text for 2nd comment."; 
var comment3:String  = "3 - text for 3rd comment."; 

i = Math.floor(Math.random()*3+1);

var commenttext:String = _root["comment"+i];
trace(commenttext);
_root.quote1.text = commenttext;

HTH

Alistair Macdonald
Web Developments
T: 01903 209917
M: 07967 661597
Skype: blueghozt
E: ali at nubz.com
  ----- Original Message ----- 
  From: Sebastian von Bischopink 
  To: Brighton New Media 
  Sent: Monday, April 10, 2006 12:12 PM
  Subject: [BNM] Converting string to variable name (Flash)


  Hi BNM,

  another little Flash problem that i can't seem to solve.

  Okay, in this example I have 3 variables (comment1..3). I randomly  
  generate a number between 1 and 3, and add it to the string  
  'comment'. So when i trace it i get 'comment1..3'. So far so good,  
  but when i assign this variable 'commenttext' to the textfield it  
  displays 'comment1..3' rather then the value of the variable 'comment1'.

  So, i guess that i somehow have to "convert" the text string so it is  
  read as a variable name instead. Hope that makes sense ;)
  Source code below:

  comment1 = "1 - text for 1st comment.";
  comment2 = "2 - text for 2nd comment."; 
  comment3 = "3 - text for 3rd comment."; 

  i = Math.floor(Math.random()*3+1);
  commenttext = "comment" + i;
  trace(commenttext);
  _root.quote1.text = commenttext;

  i greatly appreciate any help,

  Seb


  -- 

  BNM info/subscription/archives: http://www.brightonnewmedia.org/

  BNM archive search: http://www.roddis.org/bnm/search.php
  BNM Del.icio.us tag: http://del.icio.us/tag/bnm/
  BNM Flickr group: http://www.flickr.com/groups/bnm/

  BNM powered by http://www.screen-play.net/



  -- 
  No virus found in this incoming message.
  Checked by AVG Free Edition.
  Version: 7.1.385 / Virus Database: 268.4.0/306 - Release Date: 09/04/2006



More information about the BNMList mailing list
BNMList is hosted by Screenlists, a Screen-Play.net service