home *** CD-ROM | disk | FTP | other *** search
/ Canadian Forces: Prepare for Takeoff as a Pilot / CF_FS_Air.iso.iso / pc / data / swf / contact_fr.swf / scripts / FPushButtonSymbol.as < prev    next >
Text File  |  2005-01-14  |  8KB  |  289 lines

  1. function FPushButtonClass()
  2. {
  3.    this.init();
  4. }
  5. FPushButtonClass.prototype = new FUIComponentClass();
  6. Object.registerClass("FPushButtonSymbol",FPushButtonClass);
  7. FPushButtonClass.prototype.init = function()
  8. {
  9.    super.setSize(this._width,this._height);
  10.    this.boundingBox_mc.unloadMovie();
  11.    this.attachMovie("fpb_states","fpbState_mc",1);
  12.    this.attachMovie("FLabelSymbol","fLabel_mc",2);
  13.    this.attachMovie("fpb_hitArea","fpb_hitArea_mc",3);
  14.    super.init();
  15.    this.btnState = false;
  16.    this.setClickHandler(this.clickHandler);
  17.    this._xscale = 100;
  18.    this._yscale = 100;
  19.    this.setSize(this.width,this.height);
  20.    if(this.label != undefined)
  21.    {
  22.       this.setLabel(this.label);
  23.    }
  24.    this.ROLE_SYSTEM_PUSHBUTTON = 43;
  25.    this.STATE_SYSTEM_PRESSED = 8;
  26.    this.EVENT_OBJECT_STATECHANGE = 32778;
  27.    this.EVENT_OBJECT_NAMECHANGE = 32780;
  28.    this._accImpl.master = this;
  29.    this._accImpl.stub = false;
  30.    this._accImpl.get_accRole = this.get_accRole;
  31.    this._accImpl.get_accName = this.get_accName;
  32.    this._accImpl.get_accState = this.get_accState;
  33.    this._accImpl.get_accDefaultAction = this.get_accDefaultAction;
  34.    this._accImpl.accDoDefaultAction = this.accDoDefaultAction;
  35. };
  36. FPushButtonClass.prototype.setHitArea = function(w, h)
  37. {
  38.    var _loc3_ = this.fpb_hitArea_mc;
  39.    this.hitArea = _loc3_;
  40.    _loc3_._visible = false;
  41.    _loc3_._width = w;
  42.    _loc3_._height = arguments.length <= 1 ? _loc3_._height : h;
  43. };
  44. FPushButtonClass.prototype.setSize = function(w, h)
  45. {
  46.    w = w >= 6 ? w : 6;
  47.    if(arguments.length > 1)
  48.    {
  49.       if(h < 6)
  50.       {
  51.          h = 6;
  52.       }
  53.    }
  54.    super.setSize(w,h);
  55.    this.setLabel(this.getLabel());
  56.    this.arrangeLabel();
  57.    this.setHitArea(w,h);
  58.    this.boundingBox_mc._width = w;
  59.    this.boundingBox_mc._height = h;
  60.    this.drawFrame();
  61.    if(this.focused)
  62.    {
  63.       super.myOnSetFocus();
  64.    }
  65.    this.initContentPos("fLabel_mc");
  66. };
  67. FPushButtonClass.prototype.arrangeLabel = function()
  68. {
  69.    var _loc2_ = this.fLabel_mc;
  70.    var _loc4_ = this.height;
  71.    var _loc5_ = this.width - 2;
  72.    var _loc3_ = 1;
  73.    this.fLabel_mc.setSize(_loc5_ - _loc3_ * 4);
  74.    _loc2_._x = _loc3_ * 3;
  75.    _loc2_._y = _loc4_ / 2 - _loc2_._height / 2;
  76. };
  77. FPushButtonClass.prototype.getLabel = function()
  78. {
  79.    return this.fLabel_mc.labelField.text;
  80. };
  81. FPushButtonClass.prototype.setLabel = function(label)
  82. {
  83.    this.fLabel_mc.setLabel(label);
  84.    this.txtFormat();
  85.    this.arrangeLabel();
  86.    if(Accessibility.isActive())
  87.    {
  88.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_NAMECHANGE);
  89.    }
  90. };
  91. FPushButtonClass.prototype.getEnabled = function()
  92. {
  93.    return this.enabled;
  94. };
  95. FPushButtonClass.prototype.setEnabled = function(enable)
  96. {
  97.    if(enable || enable == undefined)
  98.    {
  99.       this.gotoFrame(1);
  100.       this.drawFrame();
  101.       this.flabel_mc.setEnabled(true);
  102.       this.enabled = true;
  103.       super.setEnabled(true);
  104.    }
  105.    else
  106.    {
  107.       this.gotoFrame(4);
  108.       this.drawFrame();
  109.       this.flabel_mc.setEnabled(false);
  110.       this.enabled = false;
  111.       super.setEnabled(false);
  112.    }
  113. };
  114. FPushButtonClass.prototype.txtFormat = function()
  115. {
  116.    var _loc3_ = this.textStyle;
  117.    var _loc4_ = this.styleTable;
  118.    _loc3_.align = _loc4_.textAlign.value != undefined ? undefined : (_loc3_.align = "center");
  119.    _loc3_.leftMargin = _loc4_.textLeftMargin.value != undefined ? undefined : (_loc3_.leftMargin = 1);
  120.    _loc3_.rightMargin = _loc4_.textRightMargin.value != undefined ? undefined : (_loc3_.rightMargin = 1);
  121.    if(this.fLabel_mc._height > this.height)
  122.    {
  123.       super.setSize(this.width,this.fLabel_mc._height);
  124.    }
  125.    else
  126.    {
  127.       super.setSize(this.width,this.height);
  128.    }
  129.    this.fLabel_mc.labelField.setTextFormat(this.textStyle);
  130.    this.setEnabled(this.enable);
  131. };
  132. FPushButtonClass.prototype.drawFrame = function()
  133. {
  134.    var _loc3_ = 1;
  135.    var _loc7_ = 0;
  136.    var _loc6_ = 0;
  137.    var _loc11_ = this.width;
  138.    var _loc10_ = this.height;
  139.    var _loc12_ = ["up_mc","over_mc","down_mc","disabled_mc"];
  140.    var _loc5_ = _loc12_[this.fpbState_mc._currentframe - 1];
  141.    var _loc4_ = "frame";
  142.    var _loc2_ = 0;
  143.    while(_loc2_ < 6)
  144.    {
  145.       _loc7_ += _loc2_ % 2 * _loc3_;
  146.       _loc6_ += _loc2_ % 2 * _loc3_;
  147.       _loc11_ -= (_loc2_ + 1) % 2 * _loc3_;
  148.       _loc10_ -= (_loc2_ + 1) % 2 * _loc3_;
  149.       var _loc9_ = Math.abs(_loc7_ - _loc11_) + 2 * _loc3_;
  150.       var _loc8_ = Math.abs(_loc6_ - _loc10_) + 2 * _loc3_;
  151.       this.fpbState_mc[_loc5_][_loc4_ + _loc2_]._width = _loc9_;
  152.       this.fpbState_mc[_loc5_][_loc4_ + _loc2_]._height = _loc8_;
  153.       this.fpbState_mc[_loc5_][_loc4_ + _loc2_]._x = _loc7_ - _loc3_;
  154.       this.fpbState_mc[_loc5_][_loc4_ + _loc2_]._y = _loc6_ - _loc3_;
  155.       _loc2_ = _loc2_ + 1;
  156.    }
  157. };
  158. FPushButtonClass.prototype.setClickHandler = function(chng, obj)
  159. {
  160.    this.handlerObj = arguments.length >= 2 ? obj : this._parent;
  161.    this.clickHandler = chng;
  162. };
  163. FPushButtonClass.prototype.executeCallBack = function()
  164. {
  165.    this.handlerObj[this.clickHandler](this);
  166. };
  167. FPushButtonClass.prototype.initContentPos = function(mc)
  168. {
  169.    this.incrVal = 1;
  170.    this.initx = this[mc]._x - this.getBtnState() * this.incrVal;
  171.    this.inity = this[mc]._y - this.getBtnState() * this.incrVal;
  172.    this.togx = this.initx + this.incrVal;
  173.    this.togy = this.inity + this.incrVal;
  174. };
  175. FPushButtonClass.prototype.setBtnState = function(state)
  176. {
  177.    this.btnState = state;
  178.    if(state)
  179.    {
  180.       this.fLabel_mc._x = this.togx;
  181.       this.fLabel_mc._y = this.togy;
  182.    }
  183.    else
  184.    {
  185.       this.fLabel_mc._x = this.initx;
  186.       this.fLabel_mc._y = this.inity;
  187.    }
  188. };
  189. FPushButtonClass.prototype.getBtnState = function()
  190. {
  191.    return this.btnState;
  192. };
  193. FPushButtonClass.prototype.myOnSetFocus = function()
  194. {
  195.    this.focused = true;
  196.    super.myOnSetFocus();
  197. };
  198. FPushButtonClass.prototype.onPress = function()
  199. {
  200.    this.pressFocus();
  201.    this.fpbState_mc.gotoAndStop(3);
  202.    this.drawFrame();
  203.    this.setBtnState(true);
  204.    if(Accessibility.isActive())
  205.    {
  206.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_STATECHANGE,true);
  207.    }
  208. };
  209. FPushButtonClass.prototype.onRelease = function()
  210. {
  211.    this.fpbState_mc.gotoAndStop(2);
  212.    this.drawFrame();
  213.    this.executeCallBack();
  214.    this.setBtnState(false);
  215.    if(Accessibility.isActive())
  216.    {
  217.       Accessibility.sendEvent(this,0,this.EVENT_OBJECT_STATECHANGE,true);
  218.    }
  219. };
  220. FPushButtonClass.prototype.onRollOver = function()
  221. {
  222.    this.fpbState_mc.gotoAndStop(2);
  223.    this.drawFrame();
  224. };
  225. FPushButtonClass.prototype.onRollOut = function()
  226. {
  227.    this.fpbState_mc.gotoAndStop(1);
  228.    this.drawFrame();
  229. };
  230. FPushButtonClass.prototype.onReleaseOutside = function()
  231. {
  232.    this.setBtnState(false);
  233.    this.fpbState_mc.gotoAndStop(1);
  234.    this.drawFrame();
  235. };
  236. FPushButtonClass.prototype.onDragOut = function()
  237. {
  238.    this.setBtnState(false);
  239.    this.fpbState_mc.gotoAndStop(1);
  240.    this.drawFrame();
  241. };
  242. FPushButtonClass.prototype.onDragOver = function()
  243. {
  244.    this.setBtnState(true);
  245.    this.fpbState_mc.gotoAndStop(3);
  246.    this.drawFrame();
  247. };
  248. FPushButtonClass.prototype.myOnKeyDown = function()
  249. {
  250.    if(Key.getCode() == 32 && this.pressOnce == undefined)
  251.    {
  252.       this.onPress();
  253.       this.pressOnce = 1;
  254.    }
  255. };
  256. FClass.prototype.myOnKeyUp = function()
  257. {
  258.    if(Key.getCode() == 32)
  259.    {
  260.       this.onRelease();
  261.       this.pressOnce = undefined;
  262.    }
  263. };
  264. FPushButtonClass.prototype.get_accRole = function(childId)
  265. {
  266.    return this.master.ROLE_SYSTEM_PUSHBUTTON;
  267. };
  268. FPushButtonClass.prototype.get_accName = function(childId)
  269. {
  270.    return this.master.getLabel();
  271. };
  272. FPushButtonClass.prototype.get_accState = function(childId)
  273. {
  274.    if(this.pressOnce)
  275.    {
  276.       return this.master.STATE_SYSTEM_PRESSED;
  277.    }
  278.    return this.master.STATE_SYSTEM_DEFAULT;
  279. };
  280. FPushButtonClass.prototype.get_accDefaultAction = function(childId)
  281. {
  282.    return "Press";
  283. };
  284. FPushButtonClass.prototype.accDoDefaultAction = function(childId)
  285. {
  286.    this.master.onPress();
  287.    this.master.onRelease();
  288. };
  289.