[BNM] Converting string to variable name (Flash)
Sebastian von Bischopink
lists at allaboutseb.com
Mon Apr 10 12:39:54 BST 2006
Matt & Ali,
thanks for your replies. I've now changed the AS according to Ali's
suggestion and it works beautifully.
Seb
On 10 Apr 2006, at 13:23, Ali wrote:
> 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
>
>
More information about the BNMList mailing list
BNMList is hosted by Screenlists, a Screen-Play.net service