FLASH神奇的數(shù)字魔術(shù)盒子

若水221147 分享 時間:
  應(yīng)閃友要求制作一個數(shù)學(xué)小實例,名字好大,其實很小。
FLASH神奇的數(shù)字魔術(shù)盒子
  /*
  神奇的魔盒
  */
  stop();
  mc.t.restrict = ". 0-9";
  //限制輸入只能為數(shù)字
  //go 出盒數(shù)字控制 i 排列位置用 v 運動速度
  var go:Boolean = false, i:Number = 0, v:Number = 10;
  t1.text = "開始";
  btn.onPress = function() {
  //開始按鈕
  if (mc.t.text != "") {
  btn._visible = false;
  t1.text = "";
  v = 10;
  var j:Number = i+1;
  //this["m"+i] this["m"+j] 調(diào)出庫中m作為出盒數(shù)字載體
  this["m"+i] = attachMovie("m", "m"+i, _root.getNextHighestDepth());
  this["m"+j] = attachMovie("m", "m"+j, _root.getNextHighestDepth());
  mask.swapDepths(_root.getNextHighestDepth());
  //遮隹出盒數(shù)字
  this["m"+i]._x = 260;
  //出盒數(shù)字位置
  this["m"+j]._x = 260;
  this["m"+i]._y = 220;
  this["m"+j]._y = 220;
  var num:Number = Number(mc.t.text);
  //取得輸入數(shù)字
  this["m"+i].t.text = num;
  this["m"+j].t.text = 2*num;
  //2倍
  run(mc, 240, 190, this["m"+i], this["m"+j]);
  //移動進盒數(shù)
  go = true;
  }
  };
  function run(target:MovieClip, endx:Number, endy:Number, target1:MovieClip, target2:MovieClip) {
  target.onEnterFrame = function() {
  var disx:Number = (endx-this._x)/v;
  var disy:Number = (endy-this._y)/v;
  this._x += disx;
  this._y += disy;
  if (Math.abs(this._x-endx)<=1) {
  this._x = endx;
  this._y = endy;
  delete this.onEnterFrame;
  if (go) {
  v = 5;
  //移動出盒的兩個數(shù)
  run(target1, 410, endy-100+i*30);
  run(target2, 480, endy-100+i*30);
  go = false;
  i++;
  } else {
  back_btn._visible = true;
  t2.text = "再來";
  }
  }
  };
  }
  back_btn._visible = false;
  back_btn.onPress = function() {
  this._visible = false;t2.text = "";
  mc.t.text = "";
  mc._x = 90;
  //輸入文本框歸位
  mc._y = 192;
  btn._visible = true;
  t1.text = "開始";
  };
13993