使用图形(例如)方法而不给实例变量添加前缀
我是 AS3 和 Haxe 的新手,但希望找到一种方法来使用最终类(图形)中的方法,而不必总是添加实例变量前缀。
而不是这样的东西:
var gr:Graphics = flash.Lib.current.graphics;
gr.clear();
gr.beginFill(0xffffff, 1);
gr.drawRect(0,0,400,400);
我希望得到像processing.org一样工作的东西,但我想那里的很多便利来自于预处理。我查看了关于高级类型的Haxe参考,但我无法做任何事情工作到目前为止。这可能是不可能的,因为图形是最终的,但我认为问一下也没什么坏处。如果我能扩展 Graphics 的话,似乎会很容易。不管怎样,感谢您的阅读。
I'm new to AS3 and Haxe, but was hoping to find a way to use methods from a final class (Graphics) without always prefixing an instance variable.
Instead of something like this:
var gr:Graphics = flash.Lib.current.graphics;
gr.clear();
gr.beginFill(0xffffff, 1);
gr.drawRect(0,0,400,400);
I was hoping to get something that works like processing.org, but I guess a lot of the convenience there comes from the preprocessing. I looked at the Haxe reference on advanced types, but I haven't been able to make anything work so far. This probably isn't possible since Graphics is final, but I thought it wouldn't hurt to ask. It seems it would be easy if I could extend Graphics. Anyway, thanks for reading.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用“with”关键字有帮助吗?
Does using the 'with' keyword help any?
好的,这是在 Haxe 上实现非常简单的
with() {...}
模拟的代码:您可以像这样使用它:
它不会更改范围,而是查找调用表达式并添加每个表达式中的函数(主题)的第一个参数。所以上面的代码就相当于:
宏真好玩!
Ok, here's the code for implementing a very simple
with() {...}
emulation on Haxe:you use it like this:
Instead of changing the scope, it will look for call expressions and just add the first argument of the function (subject) to be in every expression. So the code above is equivalent to:
macros are so fun!
使用时可以尝试使用mixin。
例如创建一个 GraphicHelper 类:
然后在你的 Sprite 类中:
Use can try using mixin.
For example create a class GraphicHelper:
And then in your Sprite class: