Flash、ActionScript 3:将变量定义为来自其创建者的变量,而无需不断使用 Creator.var
我正在尝试将我的代码拆分为类。但有一个问题真正困扰着我。当我为函数创建一个类时,我给出了它自己的舞台。像这样
dragf:Dragfunctions = new Dragfunctions(this)
,在类中我使用它,
var stage:Object;
public function Dragfunctions(stage:Object)
{
this.stage = stage;
}
正如你所看到的,我现在可以使用 stage.var1 = "hi" 调用阶段的变量 但是当我需要多次调整该变量时,它会变得相当混乱......
有一种方法可以告诉我,当我调用 var1 时,他知道我的意思是 stage.var1 而无需调用 stage。它:
var var1 = stage.var1
然后使用
stage.var1 = var1
,但这也很不方便,有更好的方法吗?
I am trying to split up my code in classes. but there is a issue what really bothers me. when i create a class for functions i am giving its own stage. like this
dragf:Dragfunctions = new Dragfunctions(this)
and in the class i use this
var stage:Object;
public function Dragfunctions(stage:Object)
{
this.stage = stage;
}
as you can see i can now call a variable of the stage using stage.var1 = "hi"
but when i need to ajust that varable many times it gets a quite messy...
there is a way to tell that when i call var1 he knows i mean stage.var1 without need to call stage. its:
var var1 = stage.var1
and then using
stage.var1 = var1
but that is quite unhandy too is there a better way?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,使用 getter 和 setter(它们提供类似字段的语义,但允许您在使用赋值时执行自定义逻辑):
Yes, use getters and setters (which provide field-like semantics, but allow you to execute custom logic when assignment is used):