views:

189

answers:

1

Is it possible to escape from XML, to ActionScript 3 code? Take a look at the following:

<keyFrame name="myKey" delay="100ms" function="{function():void{soundCommand.execute()}}"></keyFrame>

where the

function():void{soundCommand.execute()}

part has to be interpreted as ActionScript 3. So ideally, if I query the function attribute of the keyFrame tag, I should get a reference to the function.

Any ideas? Thanks in advance!

PS: No Flex is allowed. :)

+2  A: 

ActionScript's eval statement is very, very simple compared to the standard JS, so just interpreting that statement with eval won't work.

Instead of specifying an anonymous function there it would be easier to just give a function name. You could then just look up that function on the appropriate object and run it like this:

function foo():void {
    trace("run foo!");
}

var testXML:XML = <keyFrame name="myKey" delay="100ms" function="foo"></keyFrame>;

this[testXML.@function]();
Branden Hall