Flash Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsWeb DesignFlash Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old July 25th, 2003, 03:00 PM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 424 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 22 h 39 m 26 sec
Reputation Power: 7
create dynamic actionscript syntax froma string

Hi,
I am trying to create a dynamic actionscript to do specific calculation with, for example:

stringa="16+14";
stringb=some_function (stringa);//outputting 30


or, if even possible, to be able to perform all actiopnscript, like e.g.

stringa=16;
stringb="c=String(stringa);c=c.length;";
c=some_function(stringb);//c would output 2

Is this possible in Flash MX?

greetings
Patrick

Reply With Quote
  #2  
Old July 29th, 2003, 05:08 AM
jamieB jamieB is offline
Contributing User
Dev Shed Novice (500 - 999 posts)
 
Join Date: Nov 2002
Posts: 592 jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level)jamieB User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 2 Days 1 h 56 m 16 sec
Reputation Power: 17
because the content of your string is arbitrary I think you would have to parse it looking for operators etc...so this would work:

Code:
stringa="16+14"; 
stringb=some_function (stringa);//outputting 30
trace(some_function (stringa));
function some_function(arg) {
	var operators = ["+","-","*","/","%"];
	var op = false;
	for (var i=0;i<operators.length;i++) {
		if(arg.indexOf(operators[i]) >-1) {
			op = operators[i];
			var sides = arg.split(op);
			break;
		}
	}
	switch(op) {
		case "+":
		return Number(sides[0])+Number(sides[1]);
		
		case "-":
		return Number(sides[0])-Number(sides[1]);
		
		case "*":
		return Number(sides[0])*Number(sides[1]);

		case "/":
		return Number(sides[0])/Number(sides[1]);
		
		case "%":
		return Number(sides[0])%Number(sides[1]);
		
		case false:
		return false;
	}
}

you could do a simliar thing with your second example if you knew the format it was going to be in beforehand, but not just eval(string) - that's not what eval is for.

Reply With Quote
  #3  
Old July 29th, 2003, 11:05 AM
cuboctahedron cuboctahedron is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Location: Netherlands
Posts: 424 cuboctahedron User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 Day 22 h 39 m 26 sec
Reputation Power: 7
Thanks for the code-example
It's very helpfull to me! I'll probably be up all night again to do some coding with it...

greetings and thanks
Patrick

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignFlash Help > create dynamic actionscript syntax froma string


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway