如何将关键字或实例名称作为参数传递给函数?如何通过这个(MovieClip)作为参数?
function (reference:InstanceName):void // kind of what I want
{
reference.gotoAndPlay("frameLabel");
}
如何将关键字或实例名称作为参数传递给函数?如何通过这个(MovieClip)作为参数?
function (reference:InstanceName):void // kind of what I want
{
reference.gotoAndPlay("frameLabel");
}
澄清jozzeh的正确答案:你的问题是变量的作用域。 “此”关键字的范围包含到所属对象 - 你将需要建立在你的函数调用父时间轴的适当范围:
function goTo(reference:MovieClip):void
{
reference.gotoAndPlay("Start");
}
goTo(this.root); // variable scope of "this" is now at the class level
显然,我们有时需要参数初始化,但在这种情况下 - 对'this'的引用会引发错误。如果这是一个具有变化值的函数,有时它的焦点是它自己的根,那么您需要处理方法sig之外的初始化逻辑。
祝你好运!
我从来没有见过这种被引用这样的...
的“这”一个函数中是初始化该函数的对象的引用。
例如:
var test:String = "testing the test."
test.myfunction();
function myfunction():void{
//this = the variable "test"
this.indexOf('test');
}
此外,如果你想要一个variabel传递给它应该是这样的一个功能:
var test:String = "testing the test."
myfunction(test);
function myfunction(mystring:String):void{
var indexer:Number = mystring.indexOf('test');
}