xml中的函数名称并调用该函数
我有函数和 xml 文件,其中存储了该函数和组件的名称。
<commands>
<command>
<flexObject>myObject1</flexObject>
<flexFunction>myFunction1</flexFunction>
</command>
<command>
<flexObject>myObject2</flexObject>
<flexFunction>myFunction2</flexFunction>
</command>
</commands>
我想制作函数数组,然后调用它们..就像
arr:Array = new Array();
arr.push(myObject1.myFunction1);
arr.push(myObject2.myFunction1);
arr[0]();
调用 myObject1.myFunction1 函数
一样, myObjects 和 myFunctions 是经典组件,
当我调用 setCommandsService.send
在处理程序中,该函数的名称为字符串,我不知道如何将其作为函数添加到数组中。
I have functions and xml file in which i store name of this functions and components..eg.
<commands>
<command>
<flexObject>myObject1</flexObject>
<flexFunction>myFunction1</flexFunction>
</command>
<command>
<flexObject>myObject2</flexObject>
<flexFunction>myFunction2</flexFunction>
</command>
</commands>
i want make array of functions and then call them..like as
arr:Array = new Array();
arr.push(myObject1.myFunction1);
arr.push(myObject2.myFunction1);
arr[0]();
call myObject1.myFunction1 function
myObjects and myFunctions are classic component and their functions
when i call setCommandsService.send <s:HTTPService id="setCommandsService" url="commands.xml" result="setCommandsService_resultHandler(event)"/>
in handler is name of this function as String and i dont know how can i add to array as function..
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
好的,您需要确保这些对象和函数在那里,但应该可以通过使用动作脚本的动态性质来实现:
这将用对函数的直接引用填充您的数组,从这里您只需要执行
functions [i]()
来调用它们。尽管如此,我并不同意让 XML 了解应用程序的内部工作。该 xml 可能会从外部调用任何内容,这无疑是一个安全问题。如果有的话,尝试将其抽象为您在 Flex 中解析的“操作”ID,然后 Flex 知道要做什么。Okay, you need to make sure that those objects and functions are there, but should be possible by using the dynamic nature of actionscript:
This would fill your array with direct references to the function, from here you just need to do
functions[i]()
to call them. With that said, I don't say I agree with having XML know about the internal working of your application. It could be possible for this xml to call anything from the outside, which is a definite security issue. If anything, try to abstract it to an 'action' ID that you parse in flex and then flex knows what to do.尝试:
或
Try:
or
您可能需要使用 getDefinitionByName
这仅适用于命名空间级别的函数,但不适用于静态类方法
You may need to use getDefinitionByName
This only works on namespace-level functions though not static class methods