-1

好的。所以我有一个函数,我通过它传递了一个名为 objectName的参数。不,我不知道该怎么做或解释它。就这样吧。

public function moveObject(ObjectName):void{


           //objectName now holds "myName" which is an object also

           //i would now like my variable called myNamePosition to equal 10

           //so it would need to grab the value of objectName which is myName:Object.
           //turn it into a string of some kind - myName:string
           //add "Position" to the end of it so its myNamePosition
           // make it equal to 10

           trace(myNamePosition);

    }

传递的函数参数会改变,所以我实际上不能使用“myName”。而是“objectName”。

谢谢

4

1 回答 1

1

例子:

package
{
import flash.display.MovieClip;


public class astest extends MovieClip
{
    public function astest()
    {
        init();
    }

    private var myNamePosition:int;
    private function init():void
    {
        moveObject({myName:{}})
    }

    public function moveObject(objectName:Object):void
    {
        var propName:String;
        for(propName in objectName)
            break;
        trace(propName);

        propName+="Position";
        trace(propName);

        this[propName] = 10;

        var propValue:* = this[propName];
        trace(propValue);
    }   
}
}

输出:

myName
myNamePosition
10

这是你需要的吗?

于 2013-02-07T13:37:53.443 回答