home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Demo / elearn / Geografie / interfata.swf / scripts / FRadioButtonSymbol.as < prev    next >
Text File  |  2004-05-12  |  13KB  |  488 lines

  1. function FRadioButtonClass()
  2. {
  3.    this.init();
  4. }
  5. function FRadioButtonGroupClass()
  6. {
  7.    this.radioInstances = new Array();
  8. }
  9. function(groupName)
  10. {
  11.    this;
  12.    "oldGroupName";
  13.    this.radioInstances[0].groupName;
  14. }
  15. FRadioButtonClass.prototype = new FUIComponentClass();
  16. FRadioButtonGroupClass.prototype = new FUIComponentClass();
  17. Object.registerClass("FRadioButtonSymbol",FRadioButtonClass);
  18. FRadioButtonClass.prototype.init = function()
  19. {
  20.    if(this.initialState == undefined)
  21.    {
  22.       this.selected = false;
  23.    }
  24.    else
  25.    {
  26.       this.selected = this.initialState;
  27.    }
  28.    super.setSize(this._width,this._height);
  29.    this.boundingBox_mc.unloadMovie();
  30.    this.boundingBox_mc._width = 0;
  31.    this.boundingBox_mc._height = 0;
  32.    this.attachMovie("frb_hitArea","frb_hitArea_mc",1);
  33.    this.attachMovie("frb_states","frb_states_mc",2);
  34.    this.attachMovie("FLabelSymbol","fLabel_mc",3);
  35.    super.init();
  36.    this._xscale = 100;
  37.    this._yscale = 100;
  38.    this.setSize(this.width,this.height);
  39.    this.setChangeHandler(this.changeHandler);
  40.    if(this.label != undefined)
  41.    {
  42.       this.setLabel(this.label);
  43.    }
  44.    if(this.initialState == undefined)
  45.    {
  46.       this.setValue(false);
  47.    }
  48.    else
  49.    {
  50.       this.setValue(this.initialState);
  51.    }
  52.    if(this.data == "")
  53.    {
  54.       this.data = undefined;
  55.    }
  56.    else
  57.    {
  58.       this.setData(this.data);
  59.    }
  60.    this.addToRadioGroup();
  61.    this.ROLE_SYSTEM_RADIOBUTTON = 45;
  62.    this.STATE_SYSTEM_SELECTED = 16;
  63.    this.EVENT_OBJECT_STATECHANGE = 32778;
  64.    this.EVENT_OBJECT_NAMECHANGE = 32780;
  65.    this._accImpl.master = this;
  66.    this._accImpl.stub = false;
  67.    this._accImpl.get_accRole = this.get_accRole;
  68.    this._accImpl.get_accName = this.get_accName;
  69.    this._accImpl.get_accState = this.get_accState;
  70.    this._accImpl.get_accDefaultAction = this.get_accDefaultAction;
  71.    this._accImpl.accDoDefaultAction = this.accDoDefaultAction;
  72. };
  73. FRadioButtonClass.prototype.setHitArea = function(w, h)
  74. {
  75.    var hit = this.frb_hitArea_mc;
  76.    this.hitArea = hit;
  77.    if(this.frb_states_mc._width > w)
  78.    {
  79.       hit._width = this.frb_states_mc._width;
  80.    }
  81.    else
  82.    {
  83.       hit._width = w;
  84.    }
  85.    hit._visible = false;
  86.    if(arguments.length > 1)
  87.    {
  88.       hit._height = h;
  89.    }
  90. };
  91. FRadioButtonClass.prototype.txtFormat = function(pos)
  92. {
  93.    var txtS = this.textStyle;
  94.    var sTbl = this.styleTable;
  95.    txtS.align = sTbl.textAlign.value != undefined ? undefined : (txtS.align = pos);
  96.    txtS.leftMargin = sTbl.textLeftMargin.value != undefined ? undefined : (txtS.leftMargin = 0);
  97.    txtS.rightMargin = sTbl.textRightMargin.value != undefined ? undefined : (txtS.rightMargin = 0);
  98.    if(this.flabel_mc._height > this.height)
  99.    {
  100.       super.setSize(this.width,this.flabel_mc._height);
  101.    }
  102.    else
  103.    {
  104.       super.setSize(this.width,this.height);
  105.    }
  106.    this.setEnabled(this.enable);
  107. };
  108. FRadioButtonClass.prototype.setSize = function(w, h)
  109. {
  110.    this.setLabel(this.getLabel());
  111.    this.setLabelPlacement(this.labelPlacement);
  112.    if(this.frb_states_mc._height < this.flabel_mc.labelField._height)
  113.    {
  114.       super.setSize(w,this.flabel_mc.labelField._height);
  115.    }
  116.    this.setHitArea(this.width,this.height);
  117.    this.setLabelPlacement(this.labelPlacement);
  118. };
  119. FRadioButtonClass.prototype.setLabelPlacement = function(pos)
  120. {
  121.    this.setLabel(this.getLabel());
  122.    this.txtFormat(pos);
  123.    var halfLabelH = this.fLabel_mc._height / 2;
  124.    var halfFrameH = this.frb_states_mc._height / 2;
  125.    var vertCenter = halfFrameH - halfLabelH;
  126.    var radioWidth = this.frb_states_mc._width;
  127.    var frame = this.frb_states_mc;
  128.    var label = this.fLabel_mc;
  129.    var w = this.width - frame._width;
  130.    if(frame._width > this.width)
  131.    {
  132.       w = 0;
  133.    }
  134.    else
  135.    {
  136.       w = this.width - frame._width;
  137.    }
  138.    this.fLabel_mc.setSize(w);
  139.    if(pos == "right" || pos == undefined)
  140.    {
  141.       this.labelPlacement = "right";
  142.       this.frb_states_mc._x = 0;
  143.       this.fLabel_mc._x = radioWidth;
  144.       this.txtFormat("left");
  145.    }
  146.    else if(pos == "left")
  147.    {
  148.       this.labelPlacement = "left";
  149.       this.fLabel_mc._x = 0;
  150.       this.frb_states_mc._x = this.width - radioWidth;
  151.       this.txtFormat("right");
  152.    }
  153.    this.fLabel_mc._y = vertCenter;
  154.    this.frb_hitArea_mc._y = vertCenter;
  155.    this.setLabel(this.getLabel());
  156. };
  157. FRadioButtonClass.prototype.setData = function(dataValue)
  158. {
  159.    this.data = dataValue;
  160. };
  161. FRadioButtonClass.prototype.getData = function()
  162. {
  163.    return this.data;
  164. };
  165. FRadioButtonClass.prototype.getState = function()
  166. {
  167.    return this.selected;
  168. };
  169. FRadioButtonClass.prototype.getSize = function()
  170. {
  171.    return this.width;
  172. };
  173. FRadioButtonClass.prototype.getGroupName = function()
  174. {
  175.    return this.groupName;
  176. };
  177. FRadioButtonClass.prototype.setGroupName = function(groupName)
  178. {
  179.    var i = 0;
  180.    while(i < this._parent[this.groupName].radioInstances.length)
  181.    {
  182.       if(this._parent[this.groupName].radioInstances[i] == this)
  183.       {
  184.          delete this._parent[this.groupName].radioInstances[i];
  185.       }
  186.       i++;
  187.    }
  188.    this.groupName = groupName;
  189.    this.addToRadioGroup();
  190. };
  191. FRadioButtonClass.prototype.addToRadioGroup = function()
  192. {
  193.    if(this._parent[this.groupName] == undefined)
  194.    {
  195.       this._parent[this.groupName] = new FRadioButtonGroupClass();
  196.    }
  197.    this._parent[this.groupName].addRadioInstance(this);
  198. };
  199. FRadioButtonClass.prototype.setValue = function(selected)
  200. {
  201.    if(selected || selected == undefined)
  202.    {
  203.       this.setState(true);
  204.       this.focusRect.removeMovieClip();
  205.       this.executeCallBack();
  206.    }
  207.    else if(selected == false)
  208.    {
  209.       this.setState(false);
  210.    }
  211. };
  212. FRadioButtonClass.prototype.setTabState = function(selected)
  213. {
  214.    Selection.setFocus(this);
  215.    this.setState(selected);
  216.    this.drawFocusRect();
  217.    this.executeCallBack();
  218. };
  219. FRadioButtonClass.prototype.setState = function(selected)
  220. {
  221.    if(selected || selected == undefined)
  222.    {
  223.       this.tabEnabled = true;
  224.       for(var i in this._parent)
  225.       {
  226.          if(this != this._parent[i] && this._parent[i].groupName == this.groupName)
  227.          {
  228.             this._parent[i].setState(false);
  229.             this._parent[i].tabEnabled = false;
  230.          }
  231.       }
  232.    }
  233.    if(this.enable)
  234.    {
  235.       this.flabel_mc.setEnabled(true);
  236.       if(selected || selected == undefined)
  237.       {
  238.          this.frb_states_mc.gotoAndStop("selectedEnabled");
  239.          this.enabled = false;
  240.          this.selected = true;
  241.          this.tabEnabled = true;
  242.          this.tabFocused = true;
  243.       }
  244.       else
  245.       {
  246.          this.frb_states_mc.gotoAndStop("unselectedEnabled");
  247.          this.enabled = true;
  248.          this.selected = false;
  249.          this.tabEnabled = false;
  250.          var enabTrue = this._parent[this.groupName].getEnabled();
  251.          var noneSelect = this._parent[this.groupName].getValue() == undefined;
  252.          if(enabTrue && noneSelect)
  253.          {
  254.             this._parent[this.groupName].radioInstances[0].tabEnabled = true;
  255.          }
  256.       }
  257.    }
  258.    else
  259.    {
  260.       this.flabel_mc.setEnabled(false);
  261.       if(selected || selected == undefined)
  262.       {
  263.          this.frb_states_mc.gotoAndStop("selectedDisabled");
  264.          this.enabled = false;
  265.          this.selected = true;
  266.          this.tabEnabled = false;
  267.       }
  268.       else
  269.       {
  270.          this.frb_states_mc.gotoAndStop("unselectedDisabled");
  271.          this.enabled = false;
  272.          this.selected = false;
  273.          this.tabEnabled = false;
  274.       }
  275.    }
  276.    if(Accessibility.isActive())
  277.    {
  278.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_STATECHANGE,true);
  279.    }
  280. };
  281. FRadioButtonClass.prototype.getValue = function()
  282. {
  283.    if(this.selected)
  284.    {
  285.       if(this.data == "" || this.data == undefined)
  286.       {
  287.          return this.getLabel();
  288.       }
  289.       return this.data;
  290.    }
  291. };
  292. FRadioButtonClass.prototype.setEnabled = function(enable)
  293. {
  294.    if(enable == true || enable == undefined)
  295.    {
  296.       this.enable = true;
  297.       super.setEnabled(true);
  298.    }
  299.    else
  300.    {
  301.       this.enable = false;
  302.       super.setEnabled(false);
  303.    }
  304.    this.setState(this.selected);
  305.    var cgn = this._parent[this.groupName].getEnabled() == undefined;
  306.    var cgnez = this._parent[this.groupName].radioInstances[0].getEnabled() == false;
  307.    if(cgn && cgnez)
  308.    {
  309.       var i = 0;
  310.       while(i < this._parent[this.groupName].radioInstances.length)
  311.       {
  312.          if(this._parent[this.groupName].radioInstances[i].getEnabled() == true)
  313.          {
  314.             this._parent[this.groupName].radioInstances[i].tabEnabled = true;
  315.             return undefined;
  316.          }
  317.          i++;
  318.       }
  319.    }
  320. };
  321. FRadioButtonClass.prototype.getEnabled = function()
  322. {
  323.    return this.enable;
  324. };
  325. FRadioButtonClass.prototype.setLabel = function(label)
  326. {
  327.    this.fLabel_mc.setLabel(label);
  328.    this.txtFormat();
  329.    if(Accessibility.isActive())
  330.    {
  331.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_NAMECHANGE);
  332.    }
  333. };
  334. FRadioButtonClass.prototype.getLabel = function()
  335. {
  336.    return this.fLabel_mc.getLabel();
  337. };
  338. FRadioButtonClass.prototype.onPress = function()
  339. {
  340.    this.pressFocus();
  341.    this.frb_states_mc.gotoAndStop("press");
  342. };
  343. FRadioButtonClass.prototype.onRelease = function()
  344. {
  345.    this.frb_states_mc.gotoAndStop("unselectedDisabled");
  346.    this.setValue(!this.selected);
  347. };
  348. FRadioButtonClass.prototype.onReleaseOutside = function()
  349. {
  350.    this.frb_states_mc.gotoAndStop("unselectedEnabled");
  351. };
  352. FRadioButtonClass.prototype.onDragOut = function()
  353. {
  354.    this.frb_states_mc.gotoAndStop("unselectedEnabled");
  355. };
  356. FRadioButtonClass.prototype.onDragOver = function()
  357. {
  358.    this.frb_states_mc.gotoAndStop("press");
  359. };
  360. FRadioButtonClass.prototype.executeCallBack = function()
  361. {
  362.    this.handlerObj[this.changeHandler](this._parent[this.groupName]);
  363. };
  364. FRadioButtonGroupClass.prototype.addRadioInstance = function(instance)
  365. {
  366.    this.radioInstances.push(instance);
  367.    this.radioInstances[0].tabEnabled = true;
  368. };
  369. FRadioButtonGroupClass.prototype.setEnabled = function(enableFlag)
  370. {
  371.    var i = 0;
  372.    while(i < this.radioInstances.length)
  373.    {
  374.       this.radioInstances[i].setEnabled(enableFlag);
  375.       i++;
  376.    }
  377. };
  378. FRadioButtonGroupClass.prototype.getEnabled = function()
  379. {
  380.    var i = 0;
  381.    while(i < this.radioInstances.length)
  382.    {
  383.       if(this.radioInstances[i].getEnabled() != this.radioInstances[0].getEnabled())
  384.       {
  385.          return undefined;
  386.       }
  387.       i++;
  388.    }
  389.    return this.radioInstances[0].getEnabled();
  390. };
  391. FRadioButtonGroupClass.prototype.setChangeHandler = function(changeHandler, obj)
  392. {
  393.    var i = 0;
  394.    while(i < this.radioInstances.length)
  395.    {
  396.       this.radioInstances[i].setChangeHandler(changeHandler,obj);
  397.       i++;
  398.    }
  399. };
  400. FRadioButtonGroupClass.prototype.getValue = function()
  401. {
  402.    var i = 0;
  403.    while(i < this.radioInstances.length)
  404.    {
  405.       if(this.radioInstances[i].selected == true)
  406.       {
  407.          if(this.radioInstances[i].data == "" || this.radioInstances[i].data == undefined)
  408.          {
  409.             return this.radioInstances[i].getLabel();
  410.          }
  411.          return this.radioInstances[i].data;
  412.       }
  413.       i++;
  414.    }
  415. };
  416. FRadioButtonGroupClass.prototype.getData = function()
  417. {
  418.    var i = 0;
  419.    while(i < this.radioInstances.length)
  420.    {
  421.       if(this.radioInstances[i].selected)
  422.       {
  423.          return this.radioInstances[i].getData();
  424.       }
  425.       i++;
  426.    }
  427. };
  428. FRadioButtonGroupClass.prototype.getInstance = function()
  429. {
  430.    var i = 0;
  431.    while(i < this.radioInstances.length)
  432.    {
  433.       if(this.radioInstances[i].selected == true)
  434.       {
  435.          return i;
  436.       }
  437.       undefined;
  438.       i++;
  439.    }
  440. };
  441. FRadioButtonGroupClass.prototype.setValue = function(dataValue)
  442. {
  443.    var i = 0;
  444.    while(i < this.radioInstances.length)
  445.    {
  446.       if(this.radioInstances[i].data == dataValue)
  447.       {
  448.          this.radioInstances[i].setValue(true);
  449.          return undefined;
  450.       }
  451.       i++;
  452.    }
  453.    var i = 0;
  454.    while(i < this.radioInstances.length)
  455.    {
  456.       if(this.radioInstances[i].getLabel() == dataValue)
  457.       {
  458.          this.radioInstances[i].setValue(true);
  459.       }
  460.       i++;
  461.    }
  462. };
  463. FRadioButtonGroupClass.prototype.setSize = function(w)
  464. {
  465.    var i = 0;
  466.    while(i < this.radioInstances.length)
  467.    {
  468.       this.radioInstances[i].setSize(w);
  469.       i++;
  470.    }
  471. };
  472. FRadioButtonGroupClass.prototype.getSize = function()
  473. {
  474.    var widestRadio = 0;
  475.    var i = 0;
  476.    while(i < this.radioInstances.length)
  477.    {
  478.       if(this.radioInstances[i].width >= widestRadio)
  479.       {
  480.          widestRadio = this.radioInstances[i].width;
  481.       }
  482.       i++;
  483.    }
  484.    return widestRadio;
  485. };
  486. FRadioButtonGroupClass.prototype;
  487. "setGroupName";
  488.