xml中的函数名称并调用该函数

发布于 2024-11-18 01:50:52 字数 838 浏览 3 评论 0原文

我有函数和 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

り繁华旳梦境 2024-11-25 01:50:52

好的,您需要确保这些对象和函数在那里,但应该可以通过使用动作脚本的动态性质来实现:

var functions:Array = [];
for(var i:uint = 0, len:uint = xml.command.length(); i<len; i++)
{
   if(this[xml.command[i].flexObject] && this[xml.command[i].flexObject][xml.command[i].flexFunction])
   {
      functions.push(this[xml.command[i].flexObject][xml.command[i].flexFunction]);
   }
}

这将用对函数的直接引用填充您的数组,从这里您只需要执行 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:

var functions:Array = [];
for(var i:uint = 0, len:uint = xml.command.length(); i<len; i++)
{
   if(this[xml.command[i].flexObject] && this[xml.command[i].flexObject][xml.command[i].flexFunction])
   {
      functions.push(this[xml.command[i].flexObject][xml.command[i].flexFunction]);
   }
}

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.

開玄 2024-11-25 01:50:52

尝试:

this[arr[0]]();

var f:Function = Object[arr[0]] as Function; 
f.call();

Try:

this[arr[0]]();

or

var f:Function = Object[arr[0]] as Function; 
f.call();
傲性难收 2024-11-25 01:50:52

您可能需要使用 getDefinitionByName

import flash.utils.getDefinitionByName;

var function:Function = getDefinitionByName('namespace.myFunction1') as Function;

这仅适用于命名空间级别的函数,但不适用于静态类方法

You may need to use getDefinitionByName

import flash.utils.getDefinitionByName;

var function:Function = getDefinitionByName('namespace.myFunction1') as Function;

This only works on namespace-level functions though not static class methods

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文