Форум Flasher.ru

Форум Flasher.ru (http://www.flasher.ru/forum/index.php)
-   ActionScript (http://www.flasher.ru/forum/forumdisplay.php?f=5)
-   -   Подскажите, где кривы руки ( addProperty ). (http://www.flasher.ru/forum/showthread.php?t=30277)

RFMitrio 15.04.2002 15:11

Подскажите, где кривы руки ( addProperty ).
 
Вот некий скрипт, не несущий особой смысловой нагрузки:
class = function()
{
this.addProperty("s", function()
{
return(this.s);
},
function(newS)
{
trace("New value to be set to obj.s is "+newS);
this.s=2;
trace("But we will set it to "+this.s);
}
);
}
obj = new class();
obj.s=10;
trace("Now obj.s is "+obj.s);
-------------
Вывод на output:
New value to be set to obj.s is 10
But we will set it to 2
Now obj.s is 10
--
Почему? В чем ошибка?

DeliMIter 15.04.2002 15:49

Маленькая ошибка. Чтобы хранить значение проперти тебе нужно завести отдельное поле
Код:

class = function() {
 this._fs = 0;
 this.addProperty("_s",
  function() {
  return this._fs;
  },
  function(newS) {
  this._fs = 2;
  });
}

X = new class();
X._s = 10;
trace(X._s);

иначе глюки неизбежны.


Часовой пояс GMT +4, время: 07:51.

Copyright © 1999-2008 Flasher.ru. All rights reserved.
Работает на vBulletin®. Copyright ©2000 - 2026, Jelsoft Enterprises Ltd. Перевод: zCarot
Администрация сайта не несёт ответственности за любую предоставленную посетителями информацию. Подробнее см. Правила.