开发者

Using one variable for different text fields or no in AS3?

I was wondering which way it would be better to do the stuff bellow (in order to increase performance)..

var _tfShopCoins:TextField = _mcShop.tfCoins;
_tfShopCoins.mouseEnabled = false;
_tfShopCoins.text = "";

var _tfShopMoney:TextField = _mcShop.tfMoney;
_tfShopMoney.mouseEnabled = false;
_tfShopMoney.text = "";

or

var 开发者_开发百科_tfText:TextField = _mcShop.tfCoins;
_tfText.mouseEnabled = false;
_tfText.text = "";

_tfText = _mcShop.tfMoney;
_tfText.mouseEnabled = false;
_tfText.text = "";

My guess is that it's the second one as there I declare only 1 variable.


Go with the first one. I personally would never reassign a variable like you did in the second example because its less readable and the performance increase would be next to nothing.


I don't think combining them into one variable will work the way you've written it out here, since you're reassigning the _tfText variable to something else (to itself, in this case).

If you have multiple text fields with the same behavior, you could put them in an array and iterate over the items -- it might save you a few lines of code, but that's about it.


In your second example, did you mean to type "_tfText.mouseEnabled..." etc.?

In any case, neither of these approaches will have a measurable impact unless you're doing it millions of times, and you're better off directly addressing the text fields in the first place:

_mcShop.tfMoney.mouseEnabled = false;
_mcShop.tfMoney.text = "";

etc.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜