如何将 属性 作为参数传递给 actionscript 中的函数
How to pass a property as argument to function in actionscript
我得到了一个名为 mcButton
的动画片段,其 属性 为 scaleX
,我必须将其传递给操作 mcButton.scaleX.
的函数
manipulateValue(mcButton.scaleX);
function manipulateValue(mcProperty:?)
{
mcProperty += 2;
..execute other things here...
}
该函数对多个 属性 和多个动画片段执行相同的代码,因此我必须使其通用。对我如何做到这一点有帮助吗?
如果你想操作多个属性..传递 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(日本标准时间)
好的。如果你想一次性传一个属性,这个怎么样?
manipulateValue(mcButton, "scaleX");
manipulateValue(mcButton, "scaleY");
function manipulateValue(obj:MovieClip, prop: String)
{
if (obj.hasOwnProperty(prop)){
obj[prop] += 2;
}
..execute other things here...
}
我得到了一个名为 mcButton
的动画片段,其 属性 为 scaleX
,我必须将其传递给操作 mcButton.scaleX.
manipulateValue(mcButton.scaleX);
function manipulateValue(mcProperty:?)
{
mcProperty += 2;
..execute other things here...
}
该函数对多个 属性 和多个动画片段执行相同的代码,因此我必须使其通用。对我如何做到这一点有帮助吗?
如果你想操作多个属性..传递 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(日本标准时间)
好的。如果你想一次性传一个属性,这个怎么样?
manipulateValue(mcButton, "scaleX");
manipulateValue(mcButton, "scaleY");
function manipulateValue(obj:MovieClip, prop: String)
{
if (obj.hasOwnProperty(prop)){
obj[prop] += 2;
}
..execute other things here...
}