Actionscript 3 如何将属性作为参数传递给actionscript中的函数

Actionscript 3 如何将属性作为参数传递给actionscript中的函数,actionscript-3,flash,actionscript,Actionscript 3,Flash,Actionscript,我得到了一个名为mcButton的movieclip,其属性为scaleX,我要将它传递给一个操作mcButton.scaleX的函数 manipulateValue(mcButton.scaleX); function manipulateValue(mcProperty:?) { mcProperty += 2; ..execute other things here... } 该函数对几个属性和几个movieclip执行相同的代码,因此我将其设置为泛型。有关如何执行此操作

我得到了一个名为
mcButton
的movieclip,其属性为
scaleX
,我要将它传递给一个操作mcButton.scaleX的函数

manipulateValue(mcButton.scaleX);

function manipulateValue(mcProperty:?)
{
   mcProperty += 2;

   ..execute other things here...
}

该函数对几个属性和几个movieclip执行相同的代码,因此我将其设置为泛型。有关如何执行此操作的任何帮助?

如果要操作多个属性。。传递mcButton对象怎么样

manipulateValue(mcButton);

function manipulateValue(obj:MovieClip)
{
    obj.scaleX += 2;

    // manipulate other properties
    obj.scaleY += 2;
    obj.width = ....;
    obj.height = ....;

    ..execute other things here...
}
更新日期:8月19日13:55(JST)

嗯。如果你想一次传递一个属性,这个怎么样

manipulateValue(mcButton, "scaleX");
manipulateValue(mcButton, "scaleY");

function manipulateValue(obj:MovieClip, prop: String)
{
    if (obj.hasOwnProperty(prop)){
        obj[prop] += 2;
    }

    ..execute other things here...
}

看来你已经接近你想要的了。我相信您尝试使用的是通配符(例如:
函数manufactualevalue(val:*)

虽然我确信我已经读到使用通配符不是最好的做法-我不完全确定具体细节为什么,但我确信这被认为是“不好的做法”-所以尝试使用:

function manipulateValue(val:Number)
{
    // lines of code such as:
    // val += 20;
}
请注意,
scaleX
scaleY
alpha
都是
Number
值,因此使用它可以工作


如果您还想处理非
:Number
的值,最好使用上面的通配符示例。

问题是,对于特定属性(如scaleX),它将用于“If..”“else If”等情况。所以如果我们要处理M个数的属性,你必须处理NxM乘以一行代码,而实际上我们只能用N行代码来处理,那么这个解决方案有什么问题呢?只要您的所有对象都是MovieClips,这似乎很理想。yhea,但是
对象
MovieClips的
属性
。我正在寻找一种以这种方式运行它的方法:
manualevalue(mc.stageX)
manualevalue(mc.scaleY)
manualize(mc.alpha)
,等等,这取决于我们想要操作的属性。我的查询的解决方案可以使
函数在运行时变得灵活。