> I can understand that an open-ended eval() function might be a security worry

 

Yes, and there are also some other reasons why AS3 doesn't include eval() ...

 

It would make the Player larger than we'd like, because the Player would have to contain the AS3 compiler.

 

And the compiler would have to be in C++ (the language the player is written in) rather than in Java (the language that Flex tools are written in), so we'd have to maintain two copies of the compiler.

 

- Gordon

 


From: flexcoders@yahoogroups.com [mailto:flexcoders@yahoogroups.com] On Behalf Of FineLine
Sent: Tuesday, June 20, 2006 6:26 PM
To: flexcoders@yahoogroups.com
Subject: [flexcoders] E4X Interpreter

 

Hi. Yesterday, I set out on what I thought would be a quick task using Flex – an E4X interpreter, where a user can view an XML document as source and tree, type in E4X expressions, and see the result of the _expression_. Ultimately, I wanted to be able to perform assignments and see the effect (if any) on the XML. Nice little tool to help learn E4X syntax.

 

As it turns out, this is a lot more difficult than I thought. I was hoping there would be some way of evaluating an E4X _expression_ held in a string. I have found that there was an eval() function in previous versions of ActionScript, but it has been dropped. I can understand that an open-ended eval() function might be a security worry, but it seems a bit restrictive not being able to evaluate E4X expressions held as a string. I have looked into these approaches:

 

  1. Objects and Dynamic classes. These allow you to assign functions to an object or class at runtime, but only functions that are already defined within the source code. There’s no way to create new function from string. Same reasoning as eval() I guess.
  2. Event handlers for GUI objects. I found it is not possible to assign to or access the “click” property of a button, for example. Again, security reason I guess.
  3. Bindings. I have tried various ways of assigning the binding of a result field at runtime, the most successful being the BindingUtils.bindProperty method. This works with simple values and XML chains, but not with chains containing E4X features such as searching, as in the following example:

 

BindingUtils.bindProperty( txtField, "text", this, ["xdata","item","(@id=='3456')","description"] );

 

I have had a look at the generated ActionScript after compiling a project with a simple “curly braces” bind to the E4X _expression_, and can see that functions have been created to watch for changes to the XML object, and then recalculate the _expression_, see if it has changed and if so update the text field (I think…)

 

So anyway, short of rewriting the entire E4X interpretation algorithms, or relying on a new component being compiled dynamically at runtime, can anyone think of a way to do this?

 

Cheers, Tim

__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Web site design development Computer software development Software design and development
Macromedia flex Software development best practice


YAHOO! GROUPS LINKS




__,_._,___

Reply via email to