Old 07-01-2008, 18:58   #1 (permalink)
Emanuele
Junior Graphic Designer
 
Emanuele's Avatar
 
Join Date: May 2007
Location: Rome
Posts: 54
Send a message via MSN to Emanuele Send a message via Skype™ to Emanuele
Evaluating a String: AS 2.0

I have this problem.
I got an array. In these array are stored some functions like :
Code:
var ar:Array = new Array("Math.sqrt(Math.pow(BC,2)-Math.pow(AC,2))", "BH*BC");

then i have the variables BC, BH, AC:

Code:
BC = 5; BH = 5; AC = 5;

Now, how can i evaluate ar[0] with the correct values? I tried with value(), eval() and some other functions, but it doesn't work. (returns "undefined")
I used to do that with eval() or do() in Lingo (Macromedia Director), but now i have to do that in flash and I can't solve this problem.
Anybody can help?

Thanks.
Emanuele.
  Reply With Quote
Old 07-01-2008, 23:51   #2 (permalink)
proc355
Trailer Trash™
 
proc355's Avatar
 
Join Date: Sep 2006
Posts: 851
eval in actionscript doesn't work that way
store your functions… as functions:

Code:
var BC = 12; var BH = 6; var AC = 3; var functions = {}; functions.foo = function(a, b) { return Math.sqrt(Math.pow(b, 2)-Math.pow(a, 2)); }; functions.bar = function(a, b) { return a*b; }; // this gets hard to read! first way is best //var functions = {foo:function (a:Number, b) { //return Math.sqrt(Math.pow(b, 2)-Math.pow(a, 2)); //}, bar:function (a, b) { //return a*b; //}}; trace(functions.foo(AC, BC)); trace(functions.bar(AC, BC));

if you require something different - allowing a user to type in a function for example - you'll need to parse the input, which may not be trivial
__________________
meh.

Last edited by proc355 : 10-01-2008 at 03:59.
  Reply With Quote
Old 17-01-2008, 19:09   #3 (permalink)
Emanuele
Junior Graphic Designer
 
Emanuele's Avatar
 
Join Date: May 2007
Location: Rome
Posts: 54
Send a message via MSN to Emanuele Send a message via Skype™ to Emanuele
Thanks for the help. Anyway I had to parse it to make it work
Bye.
  Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search


Contact Us - Web Design Forums - Archive - Top
Search Engine Optimization by vBSEO 3.0.0 RC8