home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 March / CMCD0305.ISO / Software / Demo / Elearn / Fizica / vol1 / FXII01_b / 01young / young.swf / scripts / FCheckBoxSymbol.as < prev    next >
Text File  |  2005-01-03  |  8KB  |  317 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.       super.setSize(w,this.flabel_mc.labelField._height);
  123.    }
  124.    this.setHitArea(this.width,this.height);
  125.    this.setLabelPlacement(this.labelPlacement);
  126. };
  127. FCheckBoxClass.prototype.drawFocusRect = function()
  128. {
  129.    this.drawRect(-2,-2,this._width + 6,this._height - 1);
  130. };
  131. FCheckBoxClass.prototype.onPress = function()
  132. {
  133.    this.pressFocus();
  134.    _root.focusRect.removeMovieClip();
  135.    var states = this.fcb_states_mc;
  136.    if(this.getValue())
  137.    {
  138.       states.gotoAndStop("checkedPress");
  139.    }
  140. };
  141. FCheckBoxClass.prototype.onRelease = function()
  142. {
  143.    this.fcb_states_mc.gotoAndStop("up");
  144.    this.setValue(!this.checked);
  145. };
  146. FCheckBoxClass.prototype.onReleaseOutside = function()
  147. {
  148.    var states = this.fcb_states_mc;
  149.    if(this.getValue())
  150.    {
  151.       states.gotoAndStop("checkedEnabled");
  152.    }
  153.    else
  154.    {
  155.       states.gotoAndStop("up");
  156.    }
  157. };
  158. FCheckBoxClass.prototype.onDragOut = function()
  159. {
  160.    var states = this.fcb_states_mc;
  161.    if(this.getValue())
  162.    {
  163.       states.gotoAndStop("checkedEnabled");
  164.    }
  165.    else
  166.    {
  167.       states.gotoAndStop("up");
  168.    }
  169. };
  170. FCheckBoxClass.prototype.onDragOver = function()
  171. {
  172.    var states = this.fcb_states_mc;
  173.    if(this.getValue())
  174.    {
  175.       states.gotoAndStop("checkedPress");
  176.    }
  177.    else
  178.    {
  179.       states.gotoAndStop("press");
  180.    }
  181. };
  182. FCheckBoxClass.prototype.setValue = function(checkedValue)
  183. {
  184.    if(checkedValue || checkedValue == undefined)
  185.    {
  186.       this.setCheckState(checkedValue);
  187.    }
  188.    else if(checkedValue == false)
  189.    {
  190.       this.setCheckState(checkedValue);
  191.    }
  192.    this.executeCallBack();
  193.    if(Accessibility.isActive())
  194.    {
  195.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_STATECHANGE,true);
  196.    }
  197. };
  198. FCheckBoxClass.prototype.setCheckState = function(checkedValue)
  199. {
  200.    var states = this.fcb_states_mc;
  201.    if(this.enable)
  202.    {
  203.       this.flabel_mc.setEnabled(true);
  204.       if(checkedValue || checkedValue == undefined)
  205.       {
  206.          states.gotoAndStop("checkedEnabled");
  207.          this.enabled = true;
  208.          this.checked = true;
  209.       }
  210.       else
  211.       {
  212.          states.gotoAndStop("up");
  213.          this.enabled = true;
  214.          this.checked = false;
  215.       }
  216.    }
  217.    else
  218.    {
  219.       this.flabel_mc.setEnabled(false);
  220.       if(checkedValue || checkedValue == undefined)
  221.       {
  222.          states.gotoAndStop("checkedDisabled");
  223.          this.enabled = false;
  224.          this.checked = true;
  225.       }
  226.       else
  227.       {
  228.          states.gotoAndStop("uncheckedDisabled");
  229.          this.enabled = false;
  230.          this.checked = false;
  231.          this.focusRect.removeMovieClip();
  232.       }
  233.    }
  234. };
  235. FCheckBoxClass.prototype.getValue = function()
  236. {
  237.    return this.checked;
  238. };
  239. FCheckBoxClass.prototype.setEnabled = function(enable)
  240. {
  241.    if(enable == true || enable == undefined)
  242.    {
  243.       this.enable = true;
  244.       Super.setEnabled(true);
  245.    }
  246.    else
  247.    {
  248.       this.enable = false;
  249.       Super.setEnabled(false);
  250.    }
  251.    this.setCheckState(this.checked);
  252. };
  253. FCheckBoxClass.prototype.getEnabled = function()
  254. {
  255.    return this.enable;
  256. };
  257. FCheckBoxClass.prototype.setLabel = function(label)
  258. {
  259.    this.fLabel_mc.setLabel(label);
  260.    this.txtFormat();
  261.    if(Accessibility.isActive())
  262.    {
  263.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_NAMECHANGE);
  264.    }
  265. };
  266. FCheckBoxClass.prototype.getLabel = function()
  267. {
  268.    return this.fLabel_mc.labelField.text;
  269. };
  270. FCheckBoxClass.prototype.setTextColor = function(color)
  271. {
  272.    this.fLabel_mc.labelField.textColor = color;
  273. };
  274. FCheckBoxClass.prototype.myOnKeyDown = function()
  275. {
  276.    if(Key.getCode() == 32 && this.pressOnce == undefined && this.enabled == true)
  277.    {
  278.       this.setValue(!this.getValue());
  279.       this.pressOnce = true;
  280.    }
  281. };
  282. FCheckBoxClass.prototype.myOnKeyUp = function()
  283. {
  284.    if(Key.getCode() == 32)
  285.    {
  286.       this.pressOnce = undefined;
  287.    }
  288. };
  289. FCheckBoxClass.prototype.get_accRole = function(childId)
  290. {
  291.    return this.master.ROLE_SYSTEM_CHECKBUTTON;
  292. };
  293. FCheckBoxClass.prototype.get_accName = function(childId)
  294. {
  295.    return this.master.getLabel();
  296. };
  297. FCheckBoxClass.prototype.get_accState = function(childId)
  298. {
  299.    if(this.master.getValue())
  300.    {
  301.       return this.master.STATE_SYSTEM_CHECKED;
  302.    }
  303.    return 0;
  304. };
  305. FCheckBoxClass.prototype.get_accDefaultAction = function(childId)
  306. {
  307.    if(this.master.getValue())
  308.    {
  309.       return "UnCheck";
  310.    }
  311.    return "Check";
  312. };
  313. FCheckBoxClass.prototype.accDoDefaultAction = function(childId)
  314. {
  315.    this.master.setValue(!this.master.getValue());
  316. };
  317.