home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Demo / elearn / Geografie / GEO_XII_10 / 01hazardenaturale / 01hidro.swf / scripts / FCheckBoxSymbol.as < prev    next >
Text File  |  2004-05-12  |  8KB  |  324 lines

  1. function FCheckBoxClass()
  2. {
  3.    this.init();
  4. }
  5. FCheckBoxClass.prototype = new FUIComponentClass();
  6. Object.registerClass("FCheckBoxSymbol",FCheckBoxClass);
  7. FCheckBoxClass.prototype.init = function()
  8. {
  9.    super.setSize(this._width,this._height);
  10.    this.boundingBox_mc.unloadMovie();
  11.    this.attachMovie("fcb_hitArea","fcb_hitArea_mc",1);
  12.    this.attachMovie("fcb_states","fcb_states_mc",2);
  13.    this.attachMovie("FLabelSymbol","fLabel_mc",3);
  14.    super.init();
  15.    this.setChangeHandler(this.changeHandler);
  16.    this._xscale = 100;
  17.    this._yscale = 100;
  18.    this.setSize(this.width,this.height);
  19.    if(this.initialValue == undefined)
  20.    {
  21.       this.setCheckState(false);
  22.    }
  23.    else
  24.    {
  25.       this.setCheckState(this.initialValue);
  26.    }
  27.    if(this.label != undefined)
  28.    {
  29.       this.setLabel(this.label);
  30.    }
  31.    this.ROLE_SYSTEM_CHECKBUTTON = 44;
  32.    this.STATE_SYSTEM_CHECKED = 16;
  33.    this.EVENT_OBJECT_STATECHANGE = 32778;
  34.    this.EVENT_OBJECT_NAMECHANGE = 32780;
  35.    this._accImpl.master = this;
  36.    this._accImpl.stub = false;
  37.    this._accImpl.get_accRole = this.get_accRole;
  38.    this._accImpl.get_accName = this.get_accName;
  39.    this._accImpl.get_accState = this.get_accState;
  40.    this._accImpl.get_accDefaultAction = this.get_accDefaultAction;
  41.    this._accImpl.accDoDefaultAction = this.accDoDefaultAction;
  42. };
  43. FCheckBoxClass.prototype.setLabelPlacement = function(pos)
  44. {
  45.    this.setLabel(this.getLabel());
  46.    this.txtFormat(pos);
  47.    var halfLabelH = this.fLabel_mc._height / 2;
  48.    var halfFrameH = this.fcb_states_mc._height / 2;
  49.    var vertCenter = halfFrameH - halfLabelH;
  50.    var checkWidth = this.fcb_states_mc._width;
  51.    var frame = this.fcb_states_mc;
  52.    var label = this.fLabel_mc;
  53.    var w = 0;
  54.    if(frame._width > this.width)
  55.    {
  56.       w = 0;
  57.    }
  58.    else
  59.    {
  60.       w = this.width - frame._width;
  61.    }
  62.    this.fLabel_mc.setSize(w);
  63.    if(pos == "right" || pos == undefined)
  64.    {
  65.       this.labelPlacement = "right";
  66.       this.fcb_states_mc._x = 0;
  67.       this.fLabel_mc._x = checkWidth;
  68.       this.txtFormat("left");
  69.    }
  70.    else if(pos == "left")
  71.    {
  72.       this.labelPlacement = "left";
  73.       this.fLabel_mc._x = 0;
  74.       this.fcb_states_mc._x = this.width - checkWidth;
  75.       this.txtFormat("right");
  76.    }
  77.    this.fLabel_mc._y = vertCenter;
  78.    this.fcb_hitArea_mc._y = vertCenter;
  79. };
  80. FCheckBoxClass.prototype.txtFormat = function(pos)
  81. {
  82.    var txtS = this.textStyle;
  83.    var sTbl = this.styleTable;
  84.    txtS.align = sTbl.textAlign.value != undefined ? undefined : (txtS.align = pos);
  85.    txtS.leftMargin = sTbl.textLeftMargin.value != undefined ? undefined : (txtS.leftMargin = 0);
  86.    txtS.rightMargin = sTbl.textRightMargin.value != undefined ? undefined : (txtS.rightMargin = 0);
  87.    if(this.flabel_mc._height > this.height)
  88.    {
  89.       super.setSize(this.width,this.flabel_mc._height);
  90.    }
  91.    else
  92.    {
  93.       super.setSize(this.width,this.height);
  94.    }
  95.    this.fLabel_mc.labelField.setTextFormat(this.textStyle);
  96.    this.setEnabled(this.enable);
  97. };
  98. FCheckBoxClass.prototype.setHitArea = function(w, h)
  99. {
  100.    var hit = this.fcb_hitArea_mc;
  101.    this.hitArea = hit;
  102.    if(this.fcb_states_mc._width > w)
  103.    {
  104.       hit._width = this.fcb_states_mc._width;
  105.    }
  106.    else
  107.    {
  108.       hit._width = w;
  109.    }
  110.    hit._visible = false;
  111.    if(arguments.length > 1)
  112.    {
  113.       hit._height = h;
  114.    }
  115. };
  116. FCheckBoxClass.prototype.setSize = function(w)
  117. {
  118.    this.setLabel(this.getLabel());
  119.    this.setLabelPlacement(this.labelPlacement);
  120.    if(this.fcb_states_mc._height < this.flabel_mc.labelField._height)
  121.    {
  122.       ┬º┬ºpush(this.flabel_mc);
  123.    }
  124.    else
  125.    {
  126.       this.setHitArea(this.width,this.height);
  127.       this.setLabelPlacement(this.labelPlacement);
  128.    }
  129. };
  130. FCheckBoxClass.prototype.drawFocusRect = function()
  131. {
  132.    this.drawRect(-2,-2,this._width + 6,this._height - 1);
  133. };
  134. FCheckBoxClass.prototype.onPress = function()
  135. {
  136.    this.pressFocus();
  137.    _root.focusRect.removeMovieClip();
  138.    var states = this.fcb_states_mc;
  139.    if(this.getValue())
  140.    {
  141.       states.gotoAndStop("checkedPress");
  142.    }
  143.    else
  144.    {
  145.       states.gotoAndStop("press");
  146.    }
  147. };
  148. FCheckBoxClass.prototype.onRelease = function()
  149. {
  150.    this.fcb_states_mc.gotoAndStop("up");
  151.    this.setValue(!this.checked);
  152. };
  153. FCheckBoxClass.prototype.onReleaseOutside = function()
  154. {
  155.    var states = this.fcb_states_mc;
  156.    if(this.getValue())
  157.    {
  158.       states.gotoAndStop("checkedEnabled");
  159.    }
  160.    else
  161.    {
  162.       states.gotoAndStop("up");
  163.    }
  164. };
  165. FCheckBoxClass.prototype.onDragOut = function()
  166. {
  167.    var states = this.fcb_states_mc;
  168.    if(this.getValue())
  169.    {
  170.       states.gotoAndStop("checkedEnabled");
  171.    }
  172.    else
  173.    {
  174.       states.gotoAndStop("up");
  175.    }
  176. };
  177. FCheckBoxClass.prototype.onDragOver = function()
  178. {
  179.    var states = this.fcb_states_mc;
  180.    if(this.getValue())
  181.    {
  182.       states.gotoAndStop("checkedPress");
  183.    }
  184.    else
  185.    {
  186.       states.gotoAndStop("press");
  187.    }
  188. };
  189. FCheckBoxClass.prototype.setValue = function(checkedValue)
  190. {
  191.    if(checkedValue || checkedValue == undefined)
  192.    {
  193.       this.setCheckState(checkedValue);
  194.    }
  195.    else if(checkedValue == false)
  196.    {
  197.       this.setCheckState(checkedValue);
  198.    }
  199.    this.executeCallBack();
  200.    if(Accessibility.isActive())
  201.    {
  202.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_STATECHANGE,true);
  203.    }
  204. };
  205. FCheckBoxClass.prototype.setCheckState = function(checkedValue)
  206. {
  207.    var states = this.fcb_states_mc;
  208.    if(this.enable)
  209.    {
  210.       this.flabel_mc.setEnabled(true);
  211.       if(checkedValue || checkedValue == undefined)
  212.       {
  213.          states.gotoAndStop("checkedEnabled");
  214.          this.enabled = true;
  215.          this.checked = true;
  216.       }
  217.       else
  218.       {
  219.          states.gotoAndStop("up");
  220.          this.enabled = true;
  221.          this.checked = false;
  222.       }
  223.    }
  224.    else
  225.    {
  226.       this.flabel_mc.setEnabled(false);
  227.       if(checkedValue || checkedValue == undefined)
  228.       {
  229.          states.gotoAndStop("checkedDisabled");
  230.          this.enabled = false;
  231.          this.checked = true;
  232.       }
  233.       else
  234.       {
  235.          states.gotoAndStop("uncheckedDisabled");
  236.          this.enabled = false;
  237.          this.checked = false;
  238.          this.focusRect.removeMovieClip();
  239.       }
  240.    }
  241. };
  242. FCheckBoxClass.prototype.getValue = function()
  243. {
  244.    return this.checked;
  245. };
  246. FCheckBoxClass.prototype.setEnabled = function(enable)
  247. {
  248.    if(enable == true || enable == undefined)
  249.    {
  250.       this.enable = true;
  251.       Super.setEnabled(true);
  252.    }
  253.    else
  254.    {
  255.       this.enable = false;
  256.       Super.setEnabled(false);
  257.    }
  258.    this.setCheckState(this.checked);
  259. };
  260. FCheckBoxClass.prototype.getEnabled = function()
  261. {
  262.    return this.enable;
  263. };
  264. FCheckBoxClass.prototype.setLabel = function(label)
  265. {
  266.    this.fLabel_mc.setLabel(label);
  267.    this.txtFormat();
  268.    if(Accessibility.isActive())
  269.    {
  270.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_NAMECHANGE);
  271.    }
  272. };
  273. FCheckBoxClass.prototype.getLabel = function()
  274. {
  275.    return this.fLabel_mc.labelField.text;
  276. };
  277. FCheckBoxClass.prototype.setTextColor = function(color)
  278. {
  279.    this.fLabel_mc.labelField.textColor = color;
  280. };
  281. FCheckBoxClass.prototype.myOnKeyDown = function()
  282. {
  283.    if(Key.getCode() == 32 && this.pressOnce == undefined && this.enabled == true)
  284.    {
  285.       this.setValue(!this.getValue());
  286.       this.pressOnce = true;
  287.    }
  288. };
  289. FCheckBoxClass.prototype.myOnKeyUp = function()
  290. {
  291.    if(Key.getCode() == 32)
  292.    {
  293.       this.pressOnce = undefined;
  294.    }
  295. };
  296. FCheckBoxClass.prototype.get_accRole = function(childId)
  297. {
  298.    return this.master.ROLE_SYSTEM_CHECKBUTTON;
  299. };
  300. FCheckBoxClass.prototype.get_accName = function(childId)
  301. {
  302.    return this.master.getLabel();
  303. };
  304. FCheckBoxClass.prototype.get_accState = function(childId)
  305. {
  306.    if(this.master.getValue())
  307.    {
  308.       return this.master.STATE_SYSTEM_CHECKED;
  309.    }
  310.    return 0;
  311. };
  312. FCheckBoxClass.prototype.get_accDefaultAction = function(childId)
  313. {
  314.    if(this.master.getValue())
  315.    {
  316.       return "UnCheck";
  317.    }
  318.    return "Check";
  319. };
  320. FCheckBoxClass.prototype.accDoDefaultAction = function(childId)
  321. {
  322.    this.master.setValue(!this.master.getValue());
  323. };
  324.